Solved

Why doesn't this simple bash script work?

Posted on 2008-10-29
10
276 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
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.

 

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

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

Question has a verified solution.

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

Utilizing an array to gracefully append to a list of EmailAddresses
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
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…

710 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