zshスクリプトが機能しない

zshスクリプトが機能しない

アセンブリファイルをコンパイルするために複数のコマンドを実行する必要があるため、これに対してスクリプトを作成することにしました。コンパイルする必要があるコマンドは次のとおりですhello.asm

nasm -fmacho64 hello.asm ; creates hello.o file which I need to compile with gcc
gcc -o exe hello.o -lSystem

だから私はこれを行い、結果を実行し、すべてを削除するスクリプトを作成しました。

nasm -fmacho64 $1
temp=${$1/.asm/.o}
gcc -o exe $temp -lSystem
./exe
rm exe
rm $temp

でこれを実行していますが、交換がおよびで同じように機能してzshいることを確認しました。その背後にある他のエラーと一緒に次のように言います。bashzshbad substitution

➜ ./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

$あなたの表情にはあまりにも多くの兆候があります。

$1あるいは、${1}最初のパラメータの値にアクセスするように言うこともできます。値を変更するには、2番目の形式を使用する必要があります。だからあなたが望むのは${1/.asm/.o}中括弧の中に2番目のものがないということです。$

おすすめ記事