Solved

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

Posted on 2015-01-17
7
201 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
Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

 
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Windows Script Host (WSH) has been part of Windows since Windows NT4. Windows Script Host provides architecture for building dynamic scripts that consist of a core object model, scripting hosts, and scripting engines. The key components of Window…
In this article we will discuss some EI Capitan Mail app issues and provide some manual process to resolve them.
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.

821 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