Reputation: 11
I'm getting started with bash scripting and made this little script following along a short guide but for some reason when I run the script with sh myscript
I get
myscript: 5: myscript: 0: not found running on ubuntu 12.04
here is my script below I should at least see the echo message if no args are set:
#!/bin/bash
#will do something
name=$1
username=$2
if (( $# == 0 ))
then
echo "##############################"
echo "myscript [arg1] [arg2]"
echo "arg1 is your name"
echo "and arg2 is your username"
fi
var1="Your name is ${name} and your username is ${username}"
`echo ${var1} > yourname.txt`
Upvotes: 0
Views: 3540
Reputation: 361575
`echo ${var1} > yourname.txt`
Get rid of the backticks.
echo ${var1} > yourname.txt
...for some reason when I run the script with
sh myscript
...
Don't run it that way. Make the script executable and run it directly
chmod +x myscript
./script
(or run with bash myscript
explicitly).
Upvotes: 4
Reputation: 414
It looks like that expression will work in bash but not in sh. As others pointed out change it to executable, make sure your shebang line is using bash and run it like this:
./myscript
If you want to run it with sh then it is complaining about line 5. Change it to this and it will work in /bin/sh.
if [ $# -ne 0 ]
Check out the man page for test.
Also you don't need the backticks on this line: echo ${var1} > yourname.txt
Upvotes: 1