Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Why doesn't this simple bash script work?

Posted on 2008-10-29
10
Medium Priority
?
279 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
How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

 

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 500 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

This Windows batch file is useful for organizing image files from a digital camera or other source, but can have many other uses.  It simply renames the file(s) to match their create date.  For example, if you took a picture today at 1:40pm and the …
Background Still having to process all these year-end "csv" files received from all these sources (including Government entities), sometimes we have the need to examine the contents due to data error, etc... As a "Unix" shop, our only readily …
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…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Suggested Courses

783 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