I'm having a little bit of trouble figuring out how I can use a bash array for an argument list. so far, the below code does not work.

The %s below is Midnight Commander specific.

F=(%s); for i in "${F[@]}"; \
             do G+=(--floppy_drive_$((n++))="\"$i\""); \
        done; fs-uae ${G[*]}

The problem is with this part:

fs-uae ${G[*]}

However, when I echo the last statement and use xargs, it works fine:

Open=FMAX=2; bash -c 'F=(%s); \
       for i in "${F[@]}"; \
          do G+=(--floppy_drive_$((n++))="\"$i\""); \
       done; echo ${G[*]}' | xargs -n $((FMAX*2)) fs-uae

Also it seems like I have to use bash -c because MC complains about syntax errors otherwise.

I also use this with MESS, since mess emulator needs arguments like -cart1, -cart2, -flop1, etc....

So the above code works. I can select two files with the Insert key in Midnight Commander, and just hit enter, and fs-uae will start up with the floppies I've selected. I'm just wondering if there's a better way to do this without xargs?

I've heard people say xargs is "unsafe". How worrisome is this technically?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.