Solved

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

Posted on 2015-01-17
7
194 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 84

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
Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

 
LVL 84

Accepted Solution

by:
ozo earned 500 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 84

Assisted Solution

by:ozo
ozo earned 500 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 84

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

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

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

Suggested Solutions

Recently, an awarded photographer, Selina De Maeyer (http://www.selinademaeyer.com/), completed a photo shoot of a beautiful event (http://www.sintjacobantwerpen.be/verslag-en-fotoreportage-van-de-sacramentsprocessie-door-antwerpen#thumbnails) in An…
Having just graduated from college and entered the workforce, I don’t find myself always using the tools and programs I grew accustomed to over the past four years. However, there is one program I continually find myself reverting back to…R.   So …
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

910 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now