[英]Bash config file throwing errors when sourced from Perl script
在源代碼.bash_profile
之后,有一行perl調用了bash包裝器函數
system ('source ~/.bash_profile; osascript -e \\'quit app "Chromium"\\'');
盡管包裝函數被調用並執行得很好,但是我從一個不相關的bash函數中拋出了一個錯誤:
/Users/me/.bashrc: line 9: syntax error near unexpected token `<'
/Users/me/.bashrc: line 9: ` done < <(find -L "$1" -type f -not -name *.swp -print0 | LC_COLLATE=C sort -dz)'
這是.bashrc
文件中的問題功能:
source_dir() {
while IFS= read -r -d $'\0' file; do
source_file "$file"
done < <(find -L "$1" -type f -not -name *.swp -print0 | LC_COLLATE=C sort -dz)
}
僅在通過Perl腳本加載它時,此bash函數直接采購它時不會引發錯誤。 我很好奇為什么。
我正在運行bash版本5.0.2。
perl的system
使用/bin/sh
作為外殼程序( https://perldoc.perl.org/functions/system.html )。 它不會理解bash特定的語法,例如進程替換。
您將需要顯式調用bash:
system 'bash', '-c', q{source ~/.bash_profile; osascript -e 'quit app "Chromium"'};
使用q{}
單引號機制可以避免反斜杠。
bash注釋:如果您將其作為交互式shell調用,它將自動在bashrc中運行,因此您應該能夠:
system 'bash', '-ic', q{osascript -e 'quit app "Chromium"'};
參考: https : //www.gnu.org/software/bash/manual/bashref.html#Bash-Startup-Files
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.