I have several commands I have to execute to compile my assembly file, so I decided to write a script for it. Commands I need to compile hello.asm:
nasm -fmacho64 hello.asm ; creates hello.o file which I need to compile with gcc
gcc -o exe hello.o -lSystem
So I wrote a script that does that, also executes result and deletes everything:
nasm -fmacho64 $1
temp=${$1/.asm/.o}
gcc -o exe $temp -lSystem
./exe
rm exe
rm $temp
I'm doing it on zsh, but I checked that substitution works the same on bash and zsh. And it says bad substitution and some other errors following it:
➜ ./asm_execute.sh hello.asm
./asm_execute.sh: line 2: ${$1/.asm/.o}: bad substitution
Undefined symbols for architecture x86_64:
"_main", referenced from:
implicit entry/start for main executable
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
./asm_execute.sh: line 4: ./exe: No such file or directory
rm: exe: No such file or directory
usage: rm [-f | -i] [-dPRrvW] file ...
unlink file
${$1/.asm/.o}should be${1/.asm/.o}... you should consider usingmakefor stuff like this imhozshscript, I'd give it the.zshextension or no extension at all instead of that misleading.shone (and make sure to add the right she-bang). Beware bash, zsh and POSIX sh languages are different and incompatible (both bash and zsh have a mode in which they can interpretshcode, but note that${param/pattern/replacement}is not part of theshlanguage, that comes from ksh).