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

x
?
Solved

How to execute the shell script on Mac Terminal: Command output?

Posted on 2015-01-17
7
Medium Priority
?
237 Views
Last Modified: 2015-01-24
Hi,
I'm running a .sh script to several files on Mac Terminal. The script and the files are saved in the same folder. The script looks good for the command "chmod +x script.sh". However, the output was not shown on the terminal. Just wonder what is going wrong here. Thanks.
0
Comment
Question by:skyberrie
  • 4
  • 2
7 Comments
 
LVL 85

Expert Comment

by:ozo
ID: 40555008
What was in the .sh script, how did you run it, and what output did you expect to be shown?
A chmod command does not normally produce output unless there was an error.
0
 
LVL 18

Expert Comment

by:Simon
ID: 40555718
+1 to ozo's reply. Add 'ls -al' to the end of your script if you want to check the results of your chmod command.
0
 

Author Comment

by:skyberrie
ID: 40555976
Please see the attached script. I have tried by adding 'ls -al' at the end of the script but it doesn't work too. Thanks.
Script.sh
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 85

Accepted Solution

by:
ozo earned 1500 total points
ID: 40555984
When I run that script, FileName is never set, so I get
1292860800
1294119000

The file exists

The file exists

The file exists

The file exists

...which continues for a very long time

Perhaps you meant to say
site="A"
instead of
site=“A”
When I make that change, I get a long list like
1292860800
1294119000
Data1_2010_12_20_0800.dat
The file dosn't exist
Script.28598569.sh: line 38: ./Blank: No such file or directory
Data1_2010_12_20_0830.dat
The file dosn't exist
Script.28598569.sh: line 38: ./Blank: No such file or directory
Data1_2010_12_20_0900.dat
The file dosn't exist
Script.28598569.sh: line 38: ./Blank: No such file or directory
Data1_2010_12_20_0930.dat
The file dosn't exist
0
 
LVL 85

Assisted Solution

by:ozo
ozo earned 1500 total points
ID: 40555988
Actually, that's not quite true, the above is what I get when I run it under Linux, after stripping \r characters.
When I run it as is under OSX, I get
: command not found: line 2:
: command not found: line 6:
usage: date [-jnu] [-d dst] [-r seconds] [-t west] [-v[+|-]val[ymwdHMS]] ...
            [-f fmt date | [[[mm]dd]HH]MM[[cc]yy][.ss]] [+format]
usage: date [-jnu] [-d dst] [-r seconds] [-t west] [-v[+|-]val[ymwdHMS]] ...
            [-f fmt date | [[[mm]dd]HH]MM[[cc]yy][.ss]] [+format]


: command not found: line 11:
Script.28598569.sh: line 26: syntax error near unexpected token `elif'
'cript.28598569.sh: line 26: `elif [ $site = B ]; then

After stripping \r characters, and changing
site=“A”
to
site="A"
I get
usage: date [-jnu] [-d dst] [-r seconds] [-t west] [-v[+|-]val[ymwdHMS]] ...
            [-f fmt date | [[[mm]dd]HH]MM[[cc]yy][.ss]] [+format]
usage: date [-jnu] [-d dst] [-r seconds] [-t west] [-v[+|-]val[ymwdHMS]] ...
            [-f fmt date | [[[mm]dd]HH]MM[[cc]yy][.ss]] [+format]


usage: date [-jnu] [-d dst] [-r seconds] [-t west] [-v[+|-]val[ymwdHMS]] ...
            [-f fmt date | [[[mm]dd]HH]MM[[cc]yy][.ss]] [+format]
usage: date [-jnu] [-d dst] [-r seconds] [-t west] [-v[+|-]val[ymwdHMS]] ...
            [-f fmt date | [[[mm]dd]HH]MM[[cc]yy][.ss]] [+format]
usage: date [-jnu] [-d dst] [-r seconds] [-t west] [-v[+|-]val[ymwdHMS]] ...
            [-f fmt date | [[[mm]dd]HH]MM[[cc]yy][.ss]] [+format]
usage: date [-jnu] [-d dst] [-r seconds] [-t west] [-v[+|-]val[ymwdHMS]] ...
            [-f fmt date | [[[mm]dd]HH]MM[[cc]yy][.ss]] [+format]
usage: date [-jnu] [-d dst] [-r seconds] [-t west] [-v[+|-]val[ymwdHMS]] ...
            [-f fmt date | [[[mm]dd]HH]MM[[cc]yy][.ss]] [+format]
Data1____.dat
The file dosn't exist
Script.28598569.sh: line 38: ./Blank: No such file or directory
usage: date [-jnu] [-d dst] [-r seconds] [-t west] [-v[+|-]val[ymwdHMS]] ...
            [-f fmt date | [[[mm]dd]HH]MM[[cc]yy][.ss]] [+format]
usage: date [-jnu] [-d dst] [-r seconds] [-t west] [-v[+|-]val[ymwdHMS]] ...
            [-f fmt date | [[[mm]dd]HH]MM[[cc]yy][.ss]] [+format]
usage: date [-jnu] [-d dst] [-r seconds] [-t west] [-v[+|-]val[ymwdHMS]] ...
            [-f fmt date | [[[mm]dd]HH]MM[[cc]yy][.ss]] [+format]
usage: date [-jnu] [-d dst] [-r seconds] [-t west] [-v[+|-]val[ymwdHMS]] ...
            [-f fmt date | [[[mm]dd]HH]MM[[cc]yy][.ss]] [+format]
usage: date [-jnu] [-d dst] [-r seconds] [-t west] [-v[+|-]val[ymwdHMS]] ...
            [-f fmt date | [[[mm]dd]HH]MM[[cc]yy][.ss]] [+format]
usage: date [-jnu] [-d dst] [-r seconds] [-t west] [-v[+|-]val[ymwdHMS]] ...
            [-f fmt date | [[[mm]dd]HH]MM[[cc]yy][.ss]] [+format]
usage: date [-jnu] [-d dst] [-r seconds] [-t west] [-v[+|-]val[ymwdHMS]] ...
            [-f fmt date | [[[mm]dd]HH]MM[[cc]yy][.ss]] [+format]
Data1____.dat
The file dosn't exist
Script.28598569.sh: line 38: ./Blank: No such file or directory
...
because the -d option to the date command means something different under OSX
0
 

Author Comment

by:skyberrie
ID: 40555992
Thank you. Will you recommend me to run it under Ubuntu?
0
 
LVL 85

Expert Comment

by:ozo
ID: 40556043
Under Ubuntu, I think the -d option means
       -d, --date=STRING
              display time described by STRING, not 'now'
which should make the script behave as described in http:#a40555984
but I don't have a Ubuntu system handy to verify that.

You should be able to check by running
man date
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Do you come here a lot? Are you lazy like me and don't want to go through the "trouble" of having to click your Dock's Safari icon and then having to click your Experts Exchange Favorites bookmark to get here? Well then this article is for you.
Article by: Justin
In light of the WannaCry ransomware attack that affected millions of Windows machines, you might wonder if your Mac needs protecting. Yes, it does and here is how to do it.
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

927 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