Bash script error in my computer but NOT on some others

the script:

waktu=$(date +"%H")
kelompok="E20"
dir_skrg=$(pwd)
if (( $waktu >= 5 && $waktu <= 10 ))
then salam="pagi"
elif (( $waktu >= 10 && $waktu <= 3 ))
then salam="siang"
elif (( $waktu >= 4 && $waktu <= 7 ))
then salam="sore"
else salam="malam"
fi
echo “Selamat $salam $kelompok dengan user $USER, sekarang pukul $waktu dan pada direktori $dir_skrg”

it gives error:

script1.sh: 5: script1.sh: 14: not found
script1.sh: 8: script1.sh: 14: not found
script1.sh: 11: script1.sh: 14: not found

but not in my friend ubuntu's. andybody knows why?

14 is the hour when I run the script, I assume for some reason it thinks 14 is a file

2

2 Answers

Looks like that is being run as a shell (sh) script rather than bash script. Try to run it like this:

bash script.sh

or enter the following as the first line of your script

#!/bin/bash

Then run as ./script.sh

2

Add #!/bin/bash to the top of your script, as the first line.

Note: This is called a shebang. More information about it may be found here.

Give your script the correct permissions.

chmod a+x <script_name>

Run your script again.

./<script_name>
4

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like