linux - see if a directory/file exists with spaces in the name -


i want ot check if path file or directory. know path exists. code below works long no spaces in path. how make work names spaces? have file name in , cannot check if exists remotely. code reads:

server=<serverip> path="/var/lib/fingerprint log.log"  if ssh root@$server test -d $path     echo "directory" else     echo "file" fi 

when have path space fails saying

test: /var/lib/fingerprint: binary operator expected

if path /var/lib/fingerprint log.log

path="/var/lib/fingerprint log.log" ssh root@$server test -d $path 

the short answer should run ssh this:

ssh root@$server test -d "'$path'" or ssh root@$server "test -d '$path'" 

the double quotes ensure $path variable expanded on local system, , single quotes passed through remote system. single quotes ensure value of $path still treated single command-line argument on remote system.

this due how ssh handles remote commands specified on command line. first, concatenates of relevant command-line arguments single space-separated string. sends string remote system, it's run shell command.

for example:

$ dne='/var/does not exist' $ ssh localhost ls $dne ls: cannot access /var/does: no such file or directory ls: cannot access not: no such file or directory ls: cannot access exist: no such file or directory  $ ssh localhost ls "$dne" ls: cannot access /var/does: no such file or directory ls: cannot access not: no such file or directory ls: cannot access exist: no such file or directory  $ ssh localhost ls "'$dne'" ls: cannot access /var/does not exist: no such file or directory 

Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -