Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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

share|improve this question
    
is this the whole file? It's obviously complaining about lines 5,8, and 11. Just wanted to make sure those are the actual lines. –  Nate Sep 20 '12 at 14:16
    
yeah it is the whole file –  Haidar M. Sep 20 '12 at 14:22
add comment

2 Answers

up vote 5 down vote accepted

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

share|improve this answer
    
ah yeah silly mistakes after all. I thought it is the same. Thanks :D –  Haidar M. Sep 20 '12 at 14:30
    
For many practical purposes, it is the same. However, bash is way richer than sh alone; for example, in sh, you would write `command` rather than $(command), or if [ $n1 -gt $n2 ] ; then rather than if (( $n1 > $n2 )) ; then. –  January Sep 20 '12 at 16:44
add comment

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>
share|improve this answer
    
thanks for the suggestion, but my script still don't works –  Haidar M. Sep 20 '12 at 14:25
    
@HaidarM. Then edit your question to give the exact errors you encounter, if they've changed. –  SirCharlo Sep 20 '12 at 14:26
    
it works actually, sorry, my mistakes :D –  Haidar M. Sep 20 '12 at 14:32
    
@HaidarM. Great! Please consider upvoting all the useful answers. This encourages people to help you in the future. Thank you! :) –  SirCharlo Sep 20 '12 at 14:32
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.