2010-03-03 22:43:54     Shell programming problem

Document created by Aaronwu Employee on Aug 20, 2013
Version 1Show Document
  • View in full screen mode

2010-03-03 22:43:54     Shell programming problem

Y F Michael Kou (UNITED STATES)

Message: 86774   

 

I was writing a shell script for my Hotplug SD device and come across some problem with I do not understand. The shell script is as following

 

#!/bin/sh

 

if [$ACTION = "add]; then

 

mount /dev/$MDEV /mnt/SD

 

else

 

umount /mnt/SD

 

fi

 

 

 

I was not able to get it to work so I modify a shell script that I get from the internet and run it using command line and the new shell script is as following

 

#!/bin/sh

 

if [ $1 > 0 ]; then

 

echo "$1 is positive"

 

else

 

echo "$1 is negative"

 

fi

 

As soon as I run the shell script, I got the error

 

TestScript : Not Found

 

and it turned out to be the #!/bin/sh line. Once I removed the line, the error becomes

 

syntax error.

 

if I removes the if-else-fi and just have the echo line, the script runs fine. It appears to me that the shell is not there to run the script. When I run the same script (with everything) on a desktop Linux machine, the script execute just fine. I am wondering if it is busybox that is causing the problem but I cannot remove busybox because mdev is from busybox.

 

If anyone have any suggestion, please let me know and I really appreciate it.

 

I am using the 2009R1 ucLinux distribution with the 2009R1.1 toolchain. I compile the kernel on coLinux.

 

 

 

Michael Kou

QuoteReplyEditDelete

 

 

2010-03-04 07:16:47     Re: Shell programming problem

Mike Frysinger (UNITED STATES)

Message: 86802   

 

your first example is missing a quote.

 

your second example is using the incorrect math operators.  you cannot use things like ">", you have to use "-lt".  read `man bash`.

QuoteReplyEditDelete

 

 

2010-03-04 11:02:05     Re: Shell programming problem

Y F Michael Kou (UNITED STATES)

Message: 86807   

 

I changed the script to -lt and still the same problem.

 

If I have a script with just

 

#!/bin/sh

 

I will get the

 

File : Not Found       error where File is the file name of the script file.

 

if I have the if-else-fi and without the #!/bin/sh, the script will not complain and will not do anything neither. However, if I added a blank line to the end of the file (after fi), it will say 'syntax error'

 

I think it must be something that I overlook during kernel compilation. Interesting thing is that I have similar problem on my coLinux on one PC but not on the other PC. The installation procedure are the same on both. I compile the kernel from both PC and use the uImage on the blackfin and same result.

 

Again, I am using 2009R1 distribution and the 2009R1.1 toolchain.

 

Thanks.

QuoteReplyEditDelete

 

 

2010-03-04 11:15:22     Re: Shell programming problem

Mike Frysinger (UNITED STATES)

Message: 86808   

 

you havent said how you're creating the file or whether you checked the perms

 

this works just fine for me on the board:

printf '#!/bin/sh\n' > test.sh

chmod a+rx test.sh

./test.sh

QuoteReplyEditDelete

 

 

2010-03-04 14:34:39     Re: Shell programming problem

Y F Michael Kou (UNITED STATES)

Message: 86810   

 

Mike:

 

Thank you Thank you. That is the problem. I was using Notepad++ on a Windoze machine and did not set it to Unix format. Minor problem but that cost me a whole day. Now I can get on with my mdev stuff.

 

Really appreciate that.

 

 

 

Michael Kou

Attachments

    Outcomes