Hello!
I have somo problems with simple scripts like this:
#!/bin/bash
echo -n "Enter your name and press [ENTER]: "
read var_name
echo "Your name is: $var_name"
When I try to run it, this error occurs: ':not a valid identifier var_name.
Why?? (I work in cygiwin)
Is there anybody out there that can help me??
Thanksss
$ which bash
/usr/bin/bash
$ cat blianna.sh
#!/usr/bin/bash
echo -n "Enter your name and press [ENTER]: "
read var_name
echo "Your name is: $var_name"
$ blianna.sh
Enter your name and press [ENTER]: Jp
Your name is: Jp
$
I agree with franklin52 without knowing about the editor called "block notes".
The script file could well be in MSDOS format where each line is terminated with carriage-return/linefeed when unix expects each line to be terminated with just linefeed. This will upsed the shell interpreter.
franklin52 post is suggesting conversion of the script from MSDOS to unix format. This is a good suggestion.
If this doesn't work, try creating a script file under a new name with your favourite unix editor (e.g. "vi") and cut/paste your post into that file.
Then make the script executable:
chmod 755 scriptname
Then execute the script from the current directory:
./scriptname
If you like to use your script/rule with some program then use it. If you like to run it using bash, then use it, not sh:
bash scriptname
or make your script executable as methyl has written and run it. In this case caller shell read the first line, find your programpath (/usr/bin/bash), start it with this scriptfile, just like previous commandline example has written.