Solved

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

Posted on 2015-01-17
7
211 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
[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
  • 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
Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

 
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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

In this article we will discuss some EI Capitan Mail app issues and provide some manual process to resolve them.
I was prompted to write this article after the recent World-Wide Ransomware outbreak. For years now, System Administrators around the world have used the excuse of "Waiting a Bit" before applying Security Patch Updates. This type of reasoning to me …
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
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…

624 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