How to place spaces in a variable in a bash shell script?

Hope this should be simple ... Here is my test.sh file:

#!/bin/bash
patch_file="/home/my dir/vtk.patch"
cmd="svn up \"$patch_file\""
$cmd

Note the space in "my dir". When I completed it,

$ ./test.sh 
Skipped '"/home/my'
Skipped 'dir/vtk.patch"'

I do not know how to place the space in a variable and still execute the command. But doing this in the bash shell works without problems.

$ svn up "/home/my dir/vtk.patch"   #WORKS!!!

Any suggestions would be greatly appreciated! I am using bash from cygwin on windows.

+3
source share
2 answers

Use eval $ cmd instead of plain $ cmd

+4
source

?
, UNIX . , . :

patch_file="/home/my\ dir/vtk.patch"

.

+2

Source: https://habr.com/ru/post/1791099/


All Articles