所以我正在尝试进行一些简单的目录遍历并运行一些脚本。
计划是使用PID=123 DIRNAME=Lalaland bash magic.sh
脚本是
echo "SCRIPT BEGIN"
PPWD=$(pwd)
BRC="/../"
echo $PPWD
echo $BRC
echo ${PPWD}${BRC}
cd ${PPWD}${BRC}
git pull
cd ../Web
nodejs server.js
echo "SCRIPT END"
echo ${PPWD}${BRC}
返回/../e/git/Gitorade
。
git status
无法运行。
cd ../Web
也以某种方式被打破。
我最后得到了这个:
SCRIPT BEGIN
/home/git/Gitorade
/../
/../e/git/Gitorade
: No such file or directorye/git/Gitorade
' is not a git command. See 'git --help'.
Did you mean this?
status
: No such file or directoryeb
SCRIPT END
我知道我可能已经犯了一些可怕的语法错误,但是我花了一些时间来调试这个,而且我对编程语言有很好的了解,但没有shell语言。是否有一些很好的教程可以用这个或一些备忘单,因为我没希望了......
编辑:
我也尝试过:
echo "SCRIPT BEGIN"
PPWD=$(pwd)
PPWD=${PPWD%$'\r'}
BRC="/../"
echo $PPWD
echo $BRC
echo "${PPWD} ${BRC}"
echo ${PPWD}${BRC}
echo $PPWD "asd"
echo $PPWD "ASD" $PPWD
echo $PPWD$PPWD
echo $BRC$BRC
echo ${PPWD}${PPWD}
cd ${PPWD}${BRC}
git status
cd ./../Gitorade
导致
SCRIPT BEGIN
/home/git/Gitorade
/../
/..//git/Gitorade
/../e/git/Gitorade
asde/git/Gitorade
ASD /home/git/Gitorade
/home/git/Gitorade
/../
/home/git/Gitorade