在〜/ .bashrc中,我定义了一些别名.但是我不能在其他shell脚本中使用它们,在那里我只能使用那里定义的别名.即使我采购了bashrc,它仍然无效.我该怎么办?
PS.我在打击.
我有一个可执行文件command.sh
#/bin/bash
alias my_command='echo ok'
my_command
Run Code Online (Sandbox Code Playgroud)
我的终端是bash.
当我像它一样运行时./command.sh,它工作正常.
当我运行它时/bin/bash ./command.sh,它找不到my_command可执行文件.
当我像它一样运行时/bin/sh ./command.sh,它工作正常.
我在这里很困惑.哪里出了问题?
我正在尝试编写一个shell脚本,它使用LibreOffice将.odt文件转换为.pdf,但却陷入了别名问题.我的内容如下~/.bash_profile:
alias soffice='/Applications/LibreOffice.app/Contents/MacOS/soffice'
Run Code Online (Sandbox Code Playgroud)
我的shell脚本中有以下行:
soffice --headless --convert-to pdf $filename
Run Code Online (Sandbox Code Playgroud)
这会产生"第14行:soffice:command not found"错误.我不知道发生了什么事,因为我可以打电话
$ alias
alias soffice='/Applications/LibreOffice.app/Contents/MacOS/soffice'
Run Code Online (Sandbox Code Playgroud)
和
$ soffice --headless --convert-to pdf thefile.odt
Run Code Online (Sandbox Code Playgroud)
也行得很好.有谁知道为什么别名在我的脚本中不起作用以及我能做些什么呢?谢谢.