variable not being used correctly by grep in shell script
I'm writing a script to resize vagrant boxes. I'm struggling with a section, which is supposed to close media. I provide the path to the vmdk file and the new size to the script.
An example path is /root/.vagrant.d/boxes/test-80/1.0.0/virtualbox/packer-centos-7.0-x86_64-disk1.vmdk
The section is as follows:
for disk in `$execsudo vboxmanage list hdds | grep -B4 $1 | grep - | grep UUID | awk \ '{print $2}'`
do
$execsudo vboxmanage closemedium disk $disk
done
It is not correctly using $1. I've tried various quoting etc. I'd appreciate some assistance.
Shell ScriptingLinux
Last Comment
mickt
8/22/2022 - Mon
Nick Upson
can you provide examples of input and add an echo of $1 to your script so we can see whats wrong with it
ozo
How is $1 being used, and what would be the correct use?
# - this is for test
echo input=$1
echo path=$path
# -
close-medium () {
for disk in `$execsudo vboxmanage list hdds | grep -B4 $1 | grep - | grep UUID | awk \ '{print $2}'`
do
$execsudo vboxmanage closemedium disk $disk
done
for clone in `$execsudo vboxmanage list hdds | grep -B4 cloned.vdi | grep - | grep UUID | awk \ '{print $2}'`
do
$execsudo vboxmanage closemedium disk $clone
done
}
ozo
What part of that script produced the output
+ /bin/sudo vboxmanage modifyhd /tmp/cloned.vdi --resize 81920
0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100%
+ close-medium
+ echo '++++++++++ Added pre loop echo here +++++++++++++'
++++++++++ Added pre loop echo here +++++++++++++
+ echo
?
Where was close-medium called?