build argument lists containing whitespace

前端 未结 5 1464
一生所求
一生所求 2020-12-01 13:24

In bash one can escape arguments that contain whitespace.

foo \"a string\"

This also works for arguments to a command or function:

5条回答
  •  自闭症患者
    2020-12-01 13:47

    I had a problem with this too as well. I was writing a bash script to backup the important files on my windows computer (cygwin). I tried the array approach too, and still had some issues. Not sure exactly how I fixed it, but here's the parts of my code that are important in case it will help you.

    WORK="d:\Work Documents\*"
    #   prompt and 7zip each file
    for x in $SVN $WEB1 $WEB2 "$WORK" $GRAPHICS $W_SQL
    do
        echo "Add $x to archive? (y/n)"
        read DO
        if [ "$DO" == "y" ]; then
            echo "compressing $x"
            7zip a $W_OUTPUT "$x"
        fi
        echo ""
    done
    

提交回复
热议问题