I written the following script which gets name of a file and then assemble and link the file. But it doesn't work. What is the problem with it?
EXPECTED_ARGS=2
if [ $# -ne $EXPECTED_ARGS ]
then
echo "[+] Assembling with Nasm."
nasm -f elf32 $1 -o $1.o
echo "[+] Linking ..."
ld $1.o -o $1
echo "[+] Done!"
else
printf "\nInvalid number of arguments, please check the inputs and try again\n"
fi;
When I run it without passing any args, it doesn't shows following error:
printf "\nInvalid number of arguments, please check the inputs and try again\n"
if...then...else
construct. Besides, contrary to the C convention, in bash$0
doesn't count as an argument, thusEXPECTED_ARGS
must be 1 in your script – Portlyif ... then ... else
statement (i.e. print an error when the actual count of arguments is not equal to the expected count of arguments, and do the job otherwise) – Portly$#
orARGC=$(( $# ))
), the question linked to as the original of the "duplicate" TOTALLY DOESN'T ANSWER that. Making me want to improve the answers here, yet I cannot. – Joellajoelle