Home Download Buy Blog Forum Support

file name with spaces from CLI

file name with spaces from CLI

Postby ubuntuwusst on Wed Dec 21, 2011 5:41 am

suppose i do have a file name like that :
"path/to/11-12-21--06-34--apt-get install converseen.txt"

it is in a shell variable, say, $DATEDFILE.

if i do :

Code: Select all
touch "${DATEDFILE}"


i get the correct file at the right place, howver doing :

Code: Select all
/usr/bin/sublime-text-2 "${DATEDFILE}"


opened 3 files :

path/to/11-12-21--06-34--apt-get
install
and
converseen.txt

how do I protect spaces for ST2 ???
ubuntuwusst
 
Posts: 3
Joined: Wed Dec 21, 2011 5:26 am

Re: file name with spaces from CLI

Postby jps on Wed Dec 21, 2011 5:51 am

It looks like you're using a shell script that doesn't quote the arguments correctly. Just use a symlink instead.
jps
Site Admin
 
Posts: 3067
Joined: Wed Mar 19, 2008 12:33 pm

Re: file name with spaces from CLI

Postby ubuntuwusst on Wed Dec 21, 2011 9:04 am

I don't think so because I've changed my script to launch Gedit instead of ST2 and it works, here is my code :
Code: Select all
#!/usr/bin/zsh
DATE=`date '+%y-%m-%d--%H-%M--'`

if [[ ${1} != '' ]]; then
   DATEDFILE="${HOME}/Installations/${DATE}${1}.txt"
   touch "${DATEDFILE}"
   #/usr/bin/sublime-text-2 "${DATEDFILE}"
   /usr/bin/gedit "${DATEDFILE}"
else
   echo -n "${DATE}" | xclip -selection c
   echo "'${DATE}' copied to the clipboard."
fi

exit 0
ubuntuwusst
 
Posts: 3
Joined: Wed Dec 21, 2011 5:26 am

Re: file name with spaces from CLI

Postby jps on Wed Dec 21, 2011 10:30 am

I suspect /usr/bin/sublime-text-2 is the culprit: check to see if it's a shell script
jps
Site Admin
 
Posts: 3067
Joined: Wed Mar 19, 2008 12:33 pm

Re: file name with spaces from CLI

Postby ubuntuwusst on Wed Dec 21, 2011 12:44 pm

jps wrote:I suspect /usr/bin/sublime-text-2 is the culprit: check to see if it's a shell script


BINGO!
U're right :
Code: Select all
$ cat  /usr/bin/sublime-text-2
#!/bin/bash
/usr/lib/sublime-text-2/sublime_text $*

then I've changed my script accordingly.
thanks a lot!!!
ubuntuwusst
 
Posts: 3
Joined: Wed Dec 21, 2011 5:26 am


Return to General Discussion

Who is online

Users browsing this forum: No registered users and 27 guests