0

I want to run a command with separate options, so i created a variable which contains the command with options.. I want to run this, but it doesnt work:

CHOICES=$("/usr/bin/whiptail $CHECKBOXCMD")

the command echo $CHECKBOXCMD shows the good parameters, copied into shell it runs

--title "Select the partitions to fill empty spaces with zeros" --checklist "NAME FSTYPE LABEL UUID FSAVAIL FSUSE%" 20 98 4 "/dev/loop122p1" "ext4 b59e3c0c-f07d-4530-beb0-10d82cd2b8eb 539,2M 100%" ON

In the script i can get

/usr/bin/whiptail --title "Select the partitions to fill empty spaces with zeros" --checklist "NAME FSTYPE LABEL UUID FSAVAIL FSUSE%" 20 98 4 "/dev/loop122p1" "ext4 b59e3c0c-f07d-4530-beb0-10d82cd2b8eb 539,2M 100%" ON : No such file or directory

Can anyone explain why ?

TheGameiswar
  • 27,855
  • 8
  • 56
  • 94
ant75
  • 1
  • 1
    Don't use a variable for commands, variable holds data, function holds code, or use an array if you like storing code and execute it. See: https://stackoverflow.com/questions/11079342/execute-command-containing-quotes-from-shell-variable – Jetchisel Oct 08 '22 at 13:12
  • 1
    Also see why [Complex variable fails](https://mywiki.wooledge.org/BashFAQ/050) – Jetchisel Oct 08 '22 at 13:14
  • your entire `whiptail` call is actually being processed as a single string (`'/usr/bin/whiptail ... 100%" ON'`) and thus the error message; remove the double quotes - `CHOICES=$(/usr/bin/whiptail $CHECKBOXCMD)` - to get around the current error message – markp-fuso Oct 08 '22 at 17:17

0 Answers0