Solved

Why doesn't this simple bash script work?

Posted on 2008-10-29
10
272 Views
Last Modified: 2013-12-26
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!
0
Comment
Question by:pzxkys
  • 5
  • 4
10 Comments
 

Author Comment

by:pzxkys
ID: 22830706
By the way: This works fine on Solaris 10.
0
 
LVL 4

Expert Comment

by:tjilp
ID: 22830752
#!/bin/bash
#
function get_fs_list ()
{
   sleep 3
}


that's it, also....use indention
0
 
LVL 40

Expert Comment

by:omarfarid
ID: 22830783
I think the problem is in the space before ()

try

#!/bin/bash
#
get_fs_list()
{
sleep 3
}
#
get_fs_list
0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 

Author Comment

by:pzxkys
ID: 22830850
Nope. With or without space after function name  and with or without indenting ... we get the same error. Interesting isn't it. :-)
0
 
LVL 40

Accepted Solution

by:
omarfarid earned 125 total points
ID: 22830920
I have this working:

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

hi
[omar@fedora8 ~]$ ./2
hiiii
[omar@fedora8 ~]$
0
 
LVL 40

Expert Comment

by:omarfarid
ID: 22830946
the script also worked and went to sleep 3 sec


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

Author Comment

by:pzxkys
ID: 22831345
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
 

Author Closing Comment

by:pzxkys
ID: 31511182
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
 
LVL 40

Expert Comment

by:omarfarid
ID: 22831389
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
 
LVL 40

Expert Comment

by:omarfarid
ID: 22831403
welcome
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The following is a collection of cases for strange behaviour when using advanced techniques in DOS batch files. You should have some basic experience in batch "programming", as I'm assuming some knowledge and not further explain the basics. For some…
Over the years I've spent many an hour playing on hardened, DMZ'd servers, with only a sub-set of the usual GNU toy's to keep me company; frequently I've needed to save and send log or data extracts from these server back to my PC, or to others, and…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question