Using the following simplified code extract:
DIR='a b'
mount_command="./mount.cpfs $loop $DIR -f $OPTS"
sudo $mount_command
Executes this line when trace is on:
+ sudo ./mount.cpfs /dev/loop0 a b -f -o default_permissions,allow_other,attr_timeout=0
But DIR
is not quoted, and so a
and b
are passed as different parameters, rather than the same to ./mount.cpfs
.
What's the best way to go about creating a command sequence like this, and then expanding it into a later command line?
Please keep in mind the code example is simplified to the core problem, I'm using mount_command
in several places with various additions before and after it, and DIR
is passed in by the user. I've tried several combinations of quoting DIR
when assigning to mount_command
, and a primitive attempt at using an array.
Example Usage of mount_command
mount_command="./mount.cpfs $loop $DIR -f $OPTS"
case "$MODE" in
gdb)
sudo gdb -return-child-result -x gdbbatch \
--args $mount_command
;;
normal)
sudo $mount_command
;;
valgrind)
sudo valgrind --track-fds=yes --leak-check=full --malloc-fill=0x80 \
--free-fill=0xff $mount_command
;;
*)
echo "Mode '$MODE' unknown"
mounted=''
exit 2
;;
esac
Update0
Please test your suggestions, I don't think the solution is straightforward.