LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
Search this Thread
Old 03-30-2011, 02:08 AM   #1
vinaytp
Member
 
Registered: Apr 2009
Location: Bengaluru, India
Distribution: RHEL 5.4, 6.0, Ubuntu 10.04
Posts: 704

Rep: Reputation: 55
Simple shell script


Hi All,

I have a script called autorun.sh in cdrom which inturn invokes install.sh in a CDROM.

autorun.sh script

Code:
#!/bin/bash
$(dirname $0) install.sh
when I try to manually execute this it gives error as:

Code:
: No such file or directoryll.sh
some characters are getting truncated...

Thanks
 
Old 03-30-2011, 02:22 AM   #2
ted_chou12
Member
 
Registered: Aug 2010
Location: Zhongli, Taoyuan
Distribution: slackware, windows, debian (armv4l GNU/Linux)
Posts: 421
Blog Entries: 28

Rep: Reputation: 2
what is this variable $(dirname $0)? if it is path to the script, it should be:
Code:
#!/bin/bash
$(dirname $0)install.sh
#if you want to have space in between:
"$(dirname $0) install.sh"
quotation is needed
 
Old 03-30-2011, 02:33 AM   #3
colucix
Moderator
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,488

Rep: Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956
Most likely you have some hidden control character in the script, like the windows terminator characters. They ususally make the shell to do weird things like this. Please, show us the output of
Code:
od -c autorun.sh
If you see the sequence \r \n you have to change it into \n, for example by means of the dos2unix utility. Anyway, if you want to run install.sh maybe you need a slash instead of a space:
Code:
$(dirname $0)/install.sh
 
Old 03-30-2011, 02:51 AM   #4
vinaytp
Member
 
Registered: Apr 2009
Location: Bengaluru, India
Distribution: RHEL 5.4, 6.0, Ubuntu 10.04
Posts: 704

Original Poster
Rep: Reputation: 55
Quote:
Originally Posted by ted_chou12 View Post
what is this variable $(dirname $0)? if it is path to the script, it should be:
Code:
#!/bin/bash
$(dirname $0)install.sh
#if you want to have space in between:
"$(dirname $0) install.sh"
quotation is needed
Thanks it worked !!
 
Old 03-30-2011, 03:32 AM   #5
colucix
Moderator
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,488

Rep: Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956
I'm curious why it works. The following:
Code:
$(dirname $0)install.sh
lacks the slash between the directory name and the name of the script, since the dirname command doesn't put a trailing slash. The second option:
Code:
"$(dirname $0) install.sh"
won't work, since a directory name alone at the beginning of a command line would throw an error, unless the directory name is . (dot). In this case the dot is interpreted as the source built-in and the install.sh script is sourced accordingly (not executed). Anyway it strongly depends on how the autorun.sh script is invoked: if you give the full path, the line above won't work. Just my .
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Need help getting started simple simple shell script dhonnoll78 Programming 6 12-17-2007 05:34 PM
simple shell script sycamorex Linux - Newbie 2 03-16-2006 06:00 PM
simple shell script Greg_courageous Programming 2 05-12-2004 04:34 PM
a simple shell script Warchief Programming 1 07-31-2003 05:01 AM
Simple C Shell script is not so simple elconde Programming 2 09-16-2001 11:53 PM


All times are GMT -5. The time now is 07:01 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration