0

So I'm trying to do some simple directory traversal and run some scripts.

The plan was to pass 2 variables to my code with PID=123 DIRNAME=Lalaland bash magic.sh

The script is

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} returns /../e/git/Gitorade.

git status does not run.

cd ../Web is also broken somehow.

I get this at the end:

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

I understand that I have probably made some terrible syntax errors but I have spent some embarassing time debugging this and I have good knowledge of programming languages but none of shell ones. Is there maybe some good tutorial for this or some cheat sheet because I am hopeless...

EDIT:

I have also tried:

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

which resulted in

SCRIPT BEGIN
/home/git/Gitorade
/../
 /..//git/Gitorade
/../e/git/Gitorade
 asde/git/Gitorade
 ASD /home/git/Gitorade
/home/git/Gitorade
/../
/home/git/Gitorade
ditoslav
  • 4,563
  • 10
  • 47
  • 79

0 Answers0