无法获取简单的bash脚本 [英] Unable to source a simple bash script

查看:47
本文介绍了无法获取简单的bash脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我理解与SO中多次提出的类似问题.但是,我在这里找不到任何通常的嫌疑犯.

 #!/bin/bashmyvar ="test"如果["$ myvar" =="test"]然后回显测试模式"科幻 

花了很多时间.谁能告诉我我想念什么?

我能够执行脚本,但无法提供相同的脚本.

错误,而源 bash:test.sh:第7行:语法错误:文件意外结束

  $其中bash/bin/bash$ bash --version3.2.57(1) 

我可以在另一台Mac上使用相同的软件.因此,这在我的Mac上几乎是错误的,但无法弄清楚它是什么.另外,不仅上述脚本,而且任何源于"if"条件的脚本我都无法获取.尝试在此处中提到的不同示例,相同的语法错误.

edit1:

  $文件test.shtest.sh:Bourne-Again Shell脚本文本可执行文件,ASCII文本 

edit2:

  $ hexdump -C test.sh00000000 23 21 2f 62 69 6e 2f 62 61 73 68 0a 6d 79 76 61 |#!/bin/bash.myva|00000010 72 3d 22 74 65 73 74 22 0a 69 66 20 5b 20 22 24 | r ="test" .if ["$ |00000020 6d 79 76 61 72 22 20 3d 3d 20 22 74 65 73 74 22 | myvar"==" test"|00000030 20 5d 0a 74 68 65 6e 0a 65 63 68 6f 20 22 54 65 |] .then.echo"Te |00000040 73 74 20 6d 6f 64 65 22 0a 66 69 0a | st模式".fi.|0000004c 

解决方案

好的.10个月后,我妻子帮我调试了这个问题.

我在.bash_profile中有一个别名 alias fi ='firebase init'

别名 fi 使bash与 if 语句混淆.

I understand similar questions to this been asked in SO multiple times. However, I couldn't find any usual suspects here.

#!/bin/bash
myvar="test"
if [ "$myvar" == "test" ]
then
echo "Test mode"
fi

Spent quite some time on it. Can anyone advice what am I missing?

I am able to execute the script, but couldn't source the same.

error while source bash: test.sh: line 7: syntax error: unexpected end of file

$ which bash
/bin/bash
$ bash --version
3.2.57(1)

I am able to get the same working on my another Mac. So, it's pretty much something wrong on my Mac, but couldn't figure out what it is. Also, not only the above-mentioned script, any script with "if" condition I couldn't source. Tried different examples mentioned here, same syntax error.

edit1:

$ file test.sh 
test.sh: Bourne-Again shell script text executable, ASCII text

edit2:

$ hexdump -C test.sh
    00000000  23 21 2f 62 69 6e 2f 62  61 73 68 0a 6d 79 76 61  |#!/bin/bash.myva|
    00000010  72 3d 22 74 65 73 74 22  0a 69 66 20 5b 20 22 24  |r="test".if [ "$|
    00000020  6d 79 76 61 72 22 20 3d  3d 20 22 74 65 73 74 22  |myvar" == "test"|
    00000030  20 5d 0a 74 68 65 6e 0a  65 63 68 6f 20 22 54 65  | ].then.echo "Te|
    00000040  73 74 20 6d 6f 64 65 22  0a 66 69 0a              |st mode".fi.|
    0000004c

解决方案

Okay. After 10 months, my wife helped me debug this problem.

I had an alias in .bash_profile alias fi='firebase init'

Alias name fi makes bash to confuse with if statement.

这篇关于无法获取简单的bash脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆