Why doesn't this simple bash script work?

The following bash script on an EMC version of redhad linux

#!/bin/bash
#
get_fs_list ()
{
sleep 3;
}
#
get_fs_list

gets

bash -v test.sh
#!/bin/bash
#
get_fs_list ()
'est.sh: line 3: syntax error near unexpected token `
'est.sh: line 3: `get_fs_list ()

What's wrong??

Thanks!
pzxkysAsked:
Who is Participating?
 
omarfaridConnect With a Mentor Commented:
I have this working:

[omar@fedora8 ~]$ cat 2
#!/bin/bash
hi()
{
 echo hiiii
}

hi
[omar@fedora8 ~]$ ./2
hiiii
[omar@fedora8 ~]$
0
 
pzxkysAuthor Commented:
By the way: This works fine on Solaris 10.
0
 
tjilpCommented:
#!/bin/bash
#
function get_fs_list ()
{
   sleep 3
}


that's it, also....use indention
0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
omarfaridCommented:
I think the problem is in the space before ()

try

#!/bin/bash
#
get_fs_list()
{
sleep 3
}
#
get_fs_list
0
 
pzxkysAuthor Commented:
Nope. With or without space after function name  and with or without indenting ... we get the same error. Interesting isn't it. :-)
0
 
omarfaridCommented:
the script also worked and went to sleep 3 sec


#!/bin/bash
#
get_fs_list()
{
sleep 3
}
#
get_fs_list
0
 
pzxkysAuthor Commented:
Okay. I put your test in a new file called hi.bash and it worked fine. I then took that same stuff and put it into my test.bash file that had the original test script in it. Got that same error. Very strange. Asumption is that there is some buried special character in the file that I can't see. I then copied the original stuff at the start of this thread into a new file and it ran fine, too.

Some buried special character in that file caused this problem.
0
 
pzxkysAuthor Commented:
Thanks for the assistance! It was the HI script that helped me solve the problem. Some garbage embedded character in the original file. I appreciate your quick response!!!
0
 
omarfaridCommented:
it could be that your script contains white space in the file. Have you created the script using vi or created it with some other editor on a say windows and the transferred it to your system?
0
 
omarfaridCommented:
welcome
0
All Courses

From novice to tech pro — start learning today.