LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 04-05-2010, 04:09 PM   #1
Devcon
Member
 
Registered: Nov 2002
Posts: 35

Rep: Reputation: 16
Bash Script - Passing command string between variables


I'm writing a script to quickly mount/unmount specific/all usb devices I plug into my laptop. I know this is a buggy way to do essentially reinvent the wheel, but I'm just practicing.

What I'd like to do:
Initially, I wanted to do what I thought was a simple thing. I wanted to attach a string to a command executed further down in the script. For example appending "MNTOPT_NTFS='-o "umask=002,utf8" -t ntfs3g -L'" to a mount command executed in a function. It ends up looking like "mount $MNTOPT_NTFS $2 $MNTDIR/$2" or something to that effect. Mount did not seem to parse the appended string correctly.

Next, I tried to store the entire mount command in a variable to be parsed later in my mount function. The problem is that the variables present within the $MNTCMD variable are not correctly parsed when $MNTCMD is called. Have a look at the script following the "vfat" condition.



Anyway, here is the script:
Code:
########################################
#!/bin/bash
#Quick Unmount Script
#Mount or Unmount USB drives by label
########################################

#Variables
#############
PROG="qmnt"
MNTDIR="/media"
DLIST=$(find $MNTDIR -mindepth 1 -maxdepth 1 -type d | awk -F"/" '{print$3}' 2> /dev/null)
MNTOPT_EXT2="-L"
MNTOPT_EXT3="-L"
MNTOPT_EXT4="-L"
MNTOPT_VFAT="-o umask=000 -L"
MNTOPT_NTFS="-o umask=000,utf8 -t ntfs-3g -L"

# Make sure only root can run our script
#########################################
if [[ $EUID -ne 0 ]]; then
   echo -ne "This script must be run as root. \n" 1>&2
      exit 1
      fi

#Help Function
####################
function help() {
	echo -ne "\n----------------------------------------------------------------\n"
        echo -ne "                         QUICK (U)MOUNT                         \n"
	echo -ne "----------------------------------------------------------------\n"
        echo -ne "Usage: $PROG [-OPTION] [DEVICE LABEL]\n"
        echo -ne "----------------------------------------------------------------\n"
        echo -ne "Options:  |\n"
        echo -ne "          | [-a], [--all] -> Unmount ALL Mounted USB Drives\n"
        echo -ne "          | [-l], [--list] -> List Connected USB Devices\n"
        echo -ne "          | [-m], [--mount] -> Mount Drive to $MNTDIR By Label\n"
        echo -ne "          | [-u], [--unmount] -> Unmount Drive By Label\n"
        echo -ne "----------------------------------------------------------------\n"
        echo -ne "*Simply input the device's label to mount/unmount it.\n\n"
        exit
}

#Determine Mount Options
#############################
function get_opts() {
ID=$(blkid -L $1)
FS=$(blkid -o value -s TYPE $ID)
if [ "$FS" == "ext2" ]; then 
MNTOPT=("$MNTOPT_EXT2")
elif [ "$FS" == "ext3" ]; then 
MNTOPT=("$MNTOPT_EXT3")
elif [ "$FS" == "ext4" ]; then 
MNTOPT=("$MNTOPT_EXT4")
elif [ "$FS" == "vfat" ]; then 
MNTOPT=("$MNTOPT_VFAT")
elif [ "$FS" == "ntfs" ]; then 
MNTOPT=("$MNTOPT_NTFS")
elif [ "$FS" ]; then 
echo -ne "Mount options undefined.  Please edit the script."
MNTOPT=("")
fi
}

#List Connected USB Devices
#############################
function list() {

for udi in $(/usr/bin/hal-find-by-capability --capability storage)
do
    device=$(hal-get-property --udi $udi --key block.device)
    vendor=$(hal-get-property --udi $udi --key storage.vendor)
    model=$(hal-get-property --udi $udi --key storage.model)
    if [[ $(hal-get-property --udi $udi --key storage.bus) = "usb" ]]
    then
        parent_udi=$(hal-find-by-property --key block.storage_device --string $udi)
        mount=$(hal-get-property --udi $parent_udi --key volume.mount_point)
        label=$(hal-get-property --udi $parent_udi --key volume.label)
        media_size=$(hal-get-property --udi $udi --key storage.removable.media_size)
        size=$(expr $media_size / \( 1024 \* 1024 \* 1024 \))
        printf "$label $mount "${size}GB" $device \n\n"
    fi
done
        exit 0
}

#List Mounted USB Devices
##############################
function list_mounted() {
        echo -ne "---------------------\n"
        echo -ne "Mounted USB Devices:\n"
        echo -ne "---------------------\n\n"
	echo -ne "$DLIST\n\n"
}

#On device label error
############################
function wrongdir() {
        echo -ne "\n---------------------\n"
        echo -ne "   QUICK (U)MOUNT      \n"
        echo -ne "---------------------\n\n"
        echo -ne "Device name doesn't exist.\n"
        echo -ne "Please verify your device is mounted and/or using that label.\n\n"

#Print Mounted Devices
        list_mounted
	exit $E_WDIR
}

#Unmount Function
##############################
function unmount() {
	umount "$MNTDIR/$1" > /dev/null 2>&1
	ST="$?"
	if [ "$ST" == "0" ]; then
	rmdir "$MNTDIR/$1"
        echo -ne "\n---------------------\n"
	echo -ne "<- Unmounted $1\n"
        echo -ne "---------------------\n\n"
	fi
}

#Mount Function
##############################
function qmount() {
	CKDEV=$(blkid -L $1)
	if [ ! -d "$MNTDIR/$1" ] && [ -n "$CKDEV" ]; then
	mkdir "$MNTDIR/$1"
	get_opts "$1"
	mount ${MNTOPT[@]} "$1" "$MNTDIR/$1" > /dev/null 2>&1
	ST="$?"
	if [ "$ST" == "0" ]; then
        echo -ne "\n-------------------------\n"
	echo -ne "-> Mounted $1\n"
        echo -ne "-------------------------\n\n"
	else
        echo -ne "\n-------------------------\n"
	echo -ne "Error, Code $ST. Exiting.\n"
        echo -ne "-------------------------\n\n"
	rmdir "$MNTDIR/$1"
	exit 1
	fi
	else
	echo -ne "\nLabel $1 already mounted or does not exist.\n     Please '$PROG -l' for a list of possible values\n\n"
	fi
}

#Arguments & Conditional Actions
##################################
if [[ $# -eq 0 ]]; then
        help
else
	while [ $# -ne 0 ]; do
	
	#Display Help
	##############
	if [ "$1" == "-h" ] || [ "$1" == "--help" ]; then
	help
	
	#List Connected Devices
	#######################
	elif [ "$1" == "-l" ] || [ "$1" == "--list" ]; then
	echo -ne "\nListing Connected USB Devices...\n"
	echo -ne "----------------------------------\n\n"
	list
	exit 0
	
	#Unmount All Devices in $MNTDIR
	###############################
	elif [ "$1" == "-a" ] || [ "$1" == "--all" ]; then
	for d in $DLIST; do
	unmount "$d"
	while [ "$ST" == "1" ]; do
	echo -ne "\nError, Code $ST. The device "$d" is busy with the following process(es):\n"
	echo -ne "--------------------------------------------------------------------\n\n"
	fuser -vkim "$MNTDIR/$d"
	echo -ne
	unmount "$d"
	done
	if [ "$ST" != "0" ] && [ "$ST" != "1" ]; then
	echo -ne "\nError, Code $ST. Exiting.\n"
	exit 1
	fi
	sleep 2
	done
	exit 0
	
	#Unmount Specified Device
	#########################
	elif [ "$1" == "-u" ] || [ "$1" == "--unmount" ]; then
	if [ ! -d "$MNTDIR/$2" ]; then
	wrongdir
	else
	unmount "$2"
	while [ "$ST" == "1" ]; do
	echo -ne "\nError, Code $ST. The device is busy with the following process(es):\n"
	echo -ne "--------------------------------------------------------------------\n\n"
	fuser -vkim "$MNTDIR/$2"
	echo -ne
	unmount "$2"
	done
	if [ "$ST" -gt "1" ]; then
	echo -ne "\nError, Code $ST. Exiting.\n"
	exit 1
	fi
	exit 0
	fi
	
	#Mount Specified Device
	#######################
	elif [ "$1" == "-m" ] || [ "$1" == "--mount" ]; then
	qmount "$2"
	exit 0
	
	#Display Help if no args
	########################
	elif [ -n "$1" ]; then
        help 
	fi
done
fi

exit 0
EDIT: Updated with revelations from below.

Last edited by Devcon; 04-05-2010 at 09:26 PM.
 
Old 04-05-2010, 05:58 PM   #2
colucix
Moderator
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,458

Rep: Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941
Code:
MNTCMD_VFAT='mount -o "umask=002" -L "$1" "$MNTDIR/$1"'
Here single quotes prevent shell expansion, hence $1 and $MNTDIR/$1 are interpreted literally. Actually you don't really need double quotes around the various option values. Something like
Code:
MNTCMD_VFAT="mount -o umask=002 -L $1 $MNTDIR/$1"
should be enough for your task.
 
Old 04-05-2010, 06:13 PM   #3
smeezekitty
Senior Member
 
Registered: Sep 2009
Location: Washington U.S.
Distribution: M$ Windows / Debian / Ubuntu / DSL / many others
Posts: 2,224

Rep: Reputation: 167Reputation: 167
One minor correction:
Code:
size=$(expr $media_size / \( 1000 \* 1000 \* 1000 \))
Should be:
Code:
size=$(expr $media_size / \( 1024 \* 1024 \* 1024 \))
 
Old 04-05-2010, 06:25 PM   #4
Devcon
Member
 
Registered: Nov 2002
Posts: 35

Original Poster
Rep: Reputation: 16
Quote:
Originally Posted by colucix View Post
Code:
MNTCMD_VFAT='mount -o "umask=002" -L "$1" "$MNTDIR/$1"'
Here single quotes prevent shell expansion, hence $1 and $MNTDIR/$1 are interpreted literally. Actually you don't really need double quotes around the various option values. Something like
Code:
MNTCMD_VFAT="mount -o umask=002 -L $1 $MNTDIR/$1"
should be enough for your task.
That is how I had it initially. True, the single quotes prevent shell expansion. My reasoning for this, is I do not want bash to interpret the "$1" variable at that point in the script. If it does, it returns the option (in this case -m) and a resulting mount error. So, I wanted to carry the literal string to another part of the script where it could then be expanded. Is there a way to do this? I know I could just put all my code in the function, but I wanted to make it easier to edit by having all important variables at the top.

And the double quotes I just put around variables by habit to avoid white space problems.

Thanks for the correction, and the comments.
 
Old 04-05-2010, 06:37 PM   #5
colucix
Moderator
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,458

Rep: Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941
Ok. I got the point. In function get_opts you can try to substitute:
Code:
MNTCMD=$MNTCMD_VFAT
with
Code:
MNTCMD=$(eval echo $MNTCMD_VFAT)
eval forces expansion, whereas the literal value of MNTCMD_VFAT would be preserved both by direct assignment and by a simple echo.

Last edited by colucix; 04-05-2010 at 06:39 PM.
 
Old 04-05-2010, 06:44 PM   #6
hi2arun
Member
 
Registered: Apr 2010
Distribution: Fedora
Posts: 109
Blog Entries: 4

Rep: Reputation: 33
Or perhaps, this one too...

Quote:
MNTCMD_VFAT=`echo mount -o "umask=002" -L "$1" "$MNTDIR/$1"`
 
Old 04-05-2010, 07:19 PM   #7
Devcon
Member
 
Registered: Nov 2002
Posts: 35

Original Poster
Rep: Reputation: 16
Thank you guys. I appreciate the suggestions.

Quote:
Originally Posted by colucix View Post
Ok. I got the point. In function get_opts you can try to substitute:
Code:
MNTCMD=$MNTCMD_VFAT
with
Code:
MNTCMD=$(eval echo $MNTCMD_VFAT)
eval forces expansion, whereas the literal value of MNTCMD_VFAT would be preserved both by direct assignment and by a simple echo.
I had read about the 'eval echo' command. It comes very close, with a couple small issues. My complete static variable is:
Code:
MNTCMD_VFAT='mount -o umask=002 -L "$1" "$MNTDIR/$1" > /dev/null 2>&1'
##I then eval echo the variable in the get_opts function with:
MNTCMD=$(eval echo "$MNTCMD_VFAT")
##Finally, I call it in function qmount() with:
$MNTCMD
The problem is with the "> /dev/null 2>&1", the entire variable gets sucked into the null void and not just the output from mount as intended.

Second, I grab the return code from the mount command with a #? variable in the mount function. The return code ends up always being zero as it is that of the eval echo command and not mount.

I'll do some more tests and update this post...
 
Old 04-05-2010, 07:23 PM   #8
tuxdev
Senior Member
 
Registered: Jul 2005
Distribution: Slackware
Posts: 2,011

Rep: Reputation: 110Reputation: 110
Use arrays to handle commands:
http://mywiki.wooledge.org/BashFAQ/050

Code:
DLIST=$(ls -1 $MNTDIR 2> /dev/null)
This doesn't handle pathnames with spaces correctly
http://mywiki.wooledge.org/ParsingLs

Excellent use of quotes, there's a few missing here and there, but it's not like most scripts I see. There's also some usage of [ that could easily be replaced by [[ just in case.
 
Old 04-05-2010, 08:21 PM   #9
Devcon
Member
 
Registered: Nov 2002
Posts: 35

Original Poster
Rep: Reputation: 16
How's this:
Code:
DLIST=$(find $MNTDIR -mindepth 1 -maxdepth 1 -type d | awk -F"/" '{print$3}' 2> /dev/null)
While I switch things over to arrays (nice wiki btw), I'll ask another question. Anyone know of a creative way to aggregate a list of all mounted "usb" devices by label?

I am currently fiddling with a combination of "mount -l", "blkid", and the little hal script written above. Hal can print all devices on the usb bus (mounted or not and by block device, not partition by partition). Is the only way to do this by using some fancy awk commands in comparing all 3 outputs?

EDIT: Beautiful... Using a simple array, I was able to make it work as i originally intended, appending mount options to the mount command. So that seems to be working well. I've posted the updated script in my original post. Now the only thing that remains is trying to make a list of mounted usb devices.

Thanks for the help

Last edited by Devcon; 04-05-2010 at 09:22 PM.
 
Old 04-05-2010, 11:08 PM   #10
grail
Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 7,431

Rep: Reputation: 1878Reputation: 1878Reputation: 1878Reputation: 1878Reputation: 1878Reputation: 1878Reputation: 1878Reputation: 1878Reputation: 1878Reputation: 1878Reputation: 1878
Well I have no valuable input over what the others have but just thought I would point out
some issues:

The variable ST is never set so while is never executed and if is always true
as variable undefined:

Quote:
elif [ "$1" == "-a" ] || [ "$1" == "--all" ]; then
for d in $DLIST; do
unmount "$d"
while [ "$ST" == "1" ]; do
echo -ne "\nError, Code $ST. The device "$d" is busy with the following process(es):\n"
echo -ne "--------------------------------------------------------------------\n\n"
fuser -vkim "$MNTDIR/$d"
echo -ne
unmount "$d"
done
if [ "$ST" != "0" ] && [ "$ST" != "1" ]; then
echo -ne "\nError, Code $ST. Exiting.\n"
exit 1
fi
sleep 2
done
exit 0
Same ST issue, difference here is that umount will happen and exit 0 will run everytime:

Quote:
elif [ "$1" == "-u" ] || [ "$1" == "--unmount" ]; then
if [ ! -d "$MNTDIR/$2" ]; then
wrongdir
else
unmount "$2"
while [ "$ST" == "1" ]; do
echo -ne "\nError, Code $ST. The device is busy with the following process(es):\n"
echo -ne "--------------------------------------------------------------------\n\n"
fuser -vkim "$MNTDIR/$2"
echo -ne
unmount "$2"
done
if [ "$ST" -gt "1" ]; then
echo -ne "\nError, Code $ST. Exiting.\n"
exit 1
fi
exit 0
fi
Best as I can tell, this option is an infinite loop:

Quote:
while[ $# -ne 0 ]; do
...
elif [ -n "$1" ]; then
help
fi
done
 
Old 04-06-2010, 12:04 AM   #11
tuxdev
Senior Member
 
Registered: Jul 2005
Distribution: Slackware
Posts: 2,011

Rep: Reputation: 110Reputation: 110
Code:
DLIST=$(find $MNTDIR -mindepth 1 -maxdepth 1 -type d | awk -F"/" '{print$3}' 2> /dev/null)
...
for dir in $DLIST ; do
This also exibits the exact same issue with spaces and newlines in filenames. Try using this loop:
Code:
while IFS="" read -r -d "" dir ; do
   basename="${dir%%*/}"
   ...
done < <(find "$MNTDIR" -mindepth 1 -maxdepth 1 -type d)
 
Old 04-06-2010, 06:57 PM   #12
Devcon
Member
 
Registered: Nov 2002
Posts: 35

Original Poster
Rep: Reputation: 16
Post

Quote:
Originally Posted by grail View Post
The variable ST is never set so while is never executed and if is always true
The sigterm variable is actually set within the "unmount" function. It proceeds to be passed in the loop. It works well in tests, so I think it is good.
Quote:
Best as I can tell, this option is an infinite loop:
True. As you can see, every conceivable branch in the loop ends with an exit command. The loop never needs to be terminated. Perhaps this is bad practice, but I don't see an alternative w/ my limited experience.

Anyway, I whipped up another script and had a couple questions:
  • 1. This time I used a case statement to handle parameters. My original intention was to use shift to cycle through a list of inputs by looping through the case statement. Instead I had to nest another loop for each applicable situation. The problem is the script failing if a text argument is shifted to $1 (as the case statement needs -a,-r,-l, etc). Other than my nested until loop, is there another solution to have $1 always remain the same, then have $3 become $2, $4 become $3, etc.? So I only want shift to work from $2 to $n.
  • 2. I know this isn't exactly secure (plaintext default pass) but I'm not too worried about that. I just don't like having to call openssl. Is there an alternative built in?

VSFTP User Script
Code:
#!/bin/bash
#####################################
#VSFTPD User Add/Remove/List Script
#Requires:
#	OpenSSL
#####################################

#Variables
##############
PROG="vsftp-users"
PUB_FTP="/home/ftp/public"
FTP_ROOT="/home/ftp"
PUB_MESSAGE=""$FTP_ROOT/.message""
PRIV_MESSAGE=""$FTP_ROOT/.priv_message""
PUB_PASS="public"
PRIV_PASS="privftp"

#Error Checking On
###################
set -e

#Root Test
##############
if [[ $EUID -ne 0 ]]; then
   echo -ne "This script must be run as root. \n" 1>&2
   exit 1
fi 

#Check Requirements
#####################
REQCK=$(type -P openssl)
[[ -z "$REQCK" ]] && exit $ER_REQ

#Check Message Files
#####################
[[ ! -f "$PRIV_MESSAGE" ]] && echo "Welcome to my FTP." > "$PRIV_MESSAGE"
[[ ! -f "$PUB_MESSAGE" ]] && echo "Welcome to my FTP." > "$PUB_MESSAGE"

#Help Function
######################
function help() {
        echo -ne "\n------------------------------------------------------------------\n"
        echo -ne "                       VSFTP USER MANAGER                         \n" 
        echo -ne "------------------------------------------------------------------\n"
        echo -ne "Usage: $PROG [-OPTION] [USER(S)]\n"
        echo -ne "------------------------------------------------------------------\n"
        echo -ne "Options:  |\n"
        echo -ne "          | [-a], [--add] -> Add VSFTPD User(s)\n"
        echo -ne "          | [-ap], [--addpriv] -> Add Private VSFTPD User(s)\n"
        echo -ne "          | [-l], [--list] -> List VSFTPD Users\n"
        echo -ne "          | [-h], [--help] -> Print This Help Dialogue\n"
        echo -ne "          | [-r], [--remove] -> Remove VSFTPD User(s)\n"
        echo -ne "------------------------------------------------------------------\n"
        echo -ne "Description: Add/Remove User(s) to VSFTPD.  You can list multiple \n"
        echo -ne "             users with the add and remove options separated by   \n"
        echo -ne "             white space.\n\n"
	exit 0
}


#Add User Function
######################
function add_user() {
if [[ "$PRIV" == "1" ]]; then
USER_HOME="$FTP_ROOT/$1"
mkdir "$USER_HOME"
useradd -d "$USER_HOME" -c "added as vsftpd user" -s "/sbin/nologin" -p $(openssl passwd -crypt "$PRIV_PASS") "$1"
cp "$PRIV_MESSAGE" "$USER_HOME"
chown -R "$1".ftp "$USER_HOME"
find "$USER_HOME" -type d -exec chmod 775 [] \;
find "$USER_HOME" -type f -exec chmod 664 [] \;
else
useradd -d "$PUB_FTP" -c "added as vsftpd user" -s "/sbin/nologin" -p $(openssl passwd -crypt "$PUB_PASS") "$1"
fi
}


#Remove User Function
######################
function remove_user() {
USERCK=$(cat /etc/passwd | grep $1 | awk -F":" '{print$6}')
if [[ "$USERCK" == "$FTP_ROOT/$1" ]]; then
userdel -fr "$1"
else
userdel -f "$1"
fi
}


#List User Function
######################
function list_users() {
echo -ne "\n------------------------------\n"
echo -ne "          Current Users:      \n"
echo -ne "------------------------------\n"
echo -ne "       User    |   Home     \n"
echo -ne "------------------------------\n"
cat /etc/passwd | grep vsftpd | awk -F":" '{print$1"   |   "$6}'
echo -ne "------------------------------\n\n"
exit 0
}

#Arguments & Conditional Actions
##################################

[[ -z "$1" ]] && help

while [ ! -z "$1" ]; do
   case "$1" in
      
      --add|-a)
         until [ -z "$2" ]; do
         add_user "$2"
         shift
	 done
	 exit 0
         ;;
      --addpriv|-ap)
         until [ -z "$2" ]; do
	 PRIV="1"
         add_user "$2"
         shift
	 done
	 exit 0
         ;;
      --help|-h)
         help
         ;;
      --list|-l)
         list_users
	 ;;
      --remove|-r)
         until [ -z "$2" ]; do
	 remove_user "$2"
         shift
	 done
	 exit 0
         ;;
	    *)
	 echo -ne "\n--> Parameter Undefined! Verify your syntax and try again.\n"
	 echo -ne "^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^"
	 help
	;;	
   esac
done

exit 0

Last edited by Devcon; 04-06-2010 at 07:09 PM.
 
Old 04-06-2010, 07:55 PM   #13
grail
Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 7,431

Rep: Reputation: 1878Reputation: 1878Reputation: 1878Reputation: 1878Reputation: 1878Reputation: 1878Reputation: 1878Reputation: 1878Reputation: 1878Reputation: 1878Reputation: 1878
Quote:
1. This time I used a case statement to handle parameters. My original intention was to use shift to cycle through a list of inputs by looping through the case statement. Instead I had to nest another loop for each applicable situation. The problem is the script failing if a text argument is shifted to $1 (as the case statement needs -a,-r,-l, etc). Other than my nested until loop, is there another solution to have $1 always remain the same, then have $3 become $2, $4 become $3, etc.? So I only want shift to work from $2 to $n.
Why not just use getopts: http://tldp.org/LDP/abs/html/internal.html#EX33
(Note: This however will not handle your -- options)

As for:
Quote:
The loop never needs to be terminated.
As far as I can see you could get rid of the while all together (which I see is altered in your second listing):

Quote:
while [ $# -ne 0 ]; do
This has already been confirmed by the if above that there is at least 1 argument.

Last edited by grail; 04-06-2010 at 07:56 PM.
 
Old 01-10-2011, 10:13 AM   #14
bossi
LQ Newbie
 
Registered: Jun 2007
Posts: 1

Rep: Reputation: 0
I solve my sintax problem with this example

Quote:
Originally Posted by smeezekitty View Post
One minor correction:
Code:
size=$(expr $media_size / \( 1000 \* 1000 \* 1000 \))
Should be:
Code:
size=$(expr $media_size / \( 1024 \* 1024 \* 1024 \))
Thanks for this example.....
 
  


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
escape string in bash script so it can be used in command line BuckRogers01 Linux - Software 15 08-12-2010 09:38 AM
Passing Environment variables to a shell-script kregec05 Programming 6 08-18-2009 08:27 AM
Passing cmake variables in a src2pkg script... Lufbery Slackware 24 08-05-2008 02:21 PM
Bash script - passing command as string lenzj Programming 3 08-24-2006 11:36 AM
Passing variables from AWK script to my shell script BigLarry Programming 1 06-12-2004 04:32 AM


All times are GMT -5. The time now is 04:21 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