4 ms·
The use of $@ doesn't look right to me. In the trivial case exposed here where there are no additional arguments to pass to the .c program, the shell executes
by teo_zero 1y ago
The use of $@ doesn't look right to me.
In the trivial case exposed here where there are no additional arguments to pass to the .c program, the shell executes
gcc "print.c" -o .out && exec ./.out
and it works "by chance".
In a more complex scenario where print.c expects some parameters, it won't work. For example,
./print.c a b c
will result in the shell trying to invoke
gcc "print.c" -o "a" "b" "c".out && exec ./"a" "b" "c".out
which makes no sense.
Are you sure you didn't intend $0 instead of $@ ?
- rwmj 1y agoIt's true, that's a mistake! OTOH we're trying to write self-compiling executable C scripts, so the safety, correctness and good sense ships sailed a while back.