You are not logged in.
Pages: 1
Hello, this is a script I made in /etc/rc.d/sd to mount my SD card as my home partition in my eee pc.
Here's the script:
http://pastebin.ca/1807492
The script works, but I keep getting this error.
[root@UpEarly coda]# /etc/rc.d/sd start
:: Mounting SD card... [BUSY] Waiting for SD card to exist...
Card exists!
/etc/rc.d/sd: line 20: [: too many arguments
Mounted at /home/coda
[DONE]
What's wrong with the if statement at line 20?
Last edited by DeeCodeUh (2010-02-24 00:00:54)
Offline
Does the following work?
if [ "$(df | grep $MNTPNT)"=="" ];
My Arch Linux Stuff • Forum Etiquette • Community Ethos - Arch is not for everyone
Offline
I talked to the #bash channel on irc, and they said that this was best:
if cat /proc/mounts | grep -q $MNTPNT;
They also made it clear that square brackets are not part of an if statement.
Way to go for online tutorials teaching me otherwise.
Last edited by DeeCodeUh (2010-02-24 00:37:32)
Offline
Every tutorial I've seen goes out of its way to say that [ is not part of the syntax. Did you get linked to it from ubuntu forums or something? >.>
[git] | [AURpkgs] | [arch-games]
Offline
Does the following work?
if [ "$(df | grep $MNTPNT)"=="" ];
Hmmm - I do believe there should be only _one_ equal sign!!
I make the same mistake myself - all the time ;-)
Other than that - there are more ways than one to skin a cat ...
just to give yall something else to chew on -
to check if the device is present:
dev="`blkid | grep $UUID | cut -d ':' -f 1`"
test "@$dev" = @ && die "-- device not present" # testing for an empty string can be tricky - a 'space' will not match! ...
check if actually mounted before umounting ...
df -a | grep -q "$MNTPOINT$" && umount $MNTPOINT
A common scripting error is to forget to double-quote the result of a command - that's when errors about 'unary operators' or 'too many arguments' come about ...
_Always_ quote the result of any command !!
Last edited by perbh (2010-02-24 01:24:28)
Offline
I just checked it... "==" is synonymous with "=". I was more focused on wrapping the call in quotation marks though.
My Arch Linux Stuff • Forum Etiquette • Community Ethos - Arch is not for everyone
Offline
I just checked it... "==" is synonymous with "=". I was more focused on wrapping the call in quotation marks though.
ooops *blushing* - that must be something new ... i _know_ I have had errors in the past with double equal signs (c-habit!!)
Sorry ...
Other than that - I've always had problems with
if test .... and if [ ... ], so these days if I just want to check if true or false I use '&&' or '||'.
If I want to handle both cases, I do 'if test $? -eq 0; then ...; else ...; fi'
Last edited by perbh (2010-02-24 01:30:52)
Offline
Every tutorial I've seen goes out of its way to say that [ is not part of the syntax. Did you get linked to it from ubuntu forums or something? >.>
lol
Offline
Other than that - I've always had problems with
if test .... and if [ ... ], so these days if I just want to check if true or false I use '&&' or '||'.
If I want to handle both cases, I do 'if test $? -eq 0; then ...; else ...; fi'
Maybe this will help ... "test" and "[ ]" are synonymous really.
test
[
Evaluate a conditional expression expr. Each operator and operand must be a separate argument.
When the [ form is used, the last argument to the command must be a ].
In other words... you only use test or [] in your "if" statement if your comparing one thing to another, and that will "evaluate" as being either true or false... BUT if your just checking to see if blah blah blah is true... then it's not necc to use those "test" or "[ ]".
Regarding this if statement:
if cat /proc/mounts | grep -q $MNTPNT;
Easiest way for me to remember when to use this is if you just run the command on the command line without the "if" and it returns "something", that means it is "true", if it runs and you get nothing back.. it's returning as "false".
Example: you can't very well compare/run "x = b" on the command line and have it return anything...so it has to be "evaluated"...that's where "test" or "[ ]" come into play.
But using "test" or "[ ]" to check if x does equal b, and if x does equal b it does returns true, and if x doesn't equal b it returns false.
Anyway...that's how I remember it
Last edited by crouse (2010-02-24 04:58:03)
Offline
Pages: 1