Group: comp.os.linux.help


Subject: replace space characters in bash variable
From: Gary Carroll
Date: 11/7/2007 8:42:26 PM
I have a script associated with some print queues (using tea4cups). I use the jobname to create a file that contains the results of the script. I build the jobname by: jobtitle=$TEAJOBID~`basename $TEATITLE` which will produce something like: 56~jobname.pdf (The job number, plus the name of the job less path.) The problem is if jobname contains a space. Then I might get: 56~job name.pdf which is inconvenient. Job names may contain any number of spaces, and this is especially a problem if it is a leading or trailing space, as may not be evident when viewing a job list. I tried replacing any spaces by: jobname=${jobname// /-} Oddly, this works when I type it directly in a command shell, but does NOT work when it executes as part of the script. Any suggestion as to the problem (or a better way to replace spaces?)

Subject: replace space characters in bash variable
From: ibuprofin@painkiller.example.tld (Moe Trin)
Date: 11/8/2007 1:52:41 PM
On Wed, 07 Nov 2007, in the Usenet newsgroup comp.os.linux.help, in article <garycarroll-7A79BB.20422607112007@news.charter.net>, Gary Carroll wrote: >I have a script associated with some print queues (using tea4cups). >I use the jobname to create a file that contains the results of the >script. >I build the jobname by: > >jobtitle=$TEAJOBID~`basename $TEATITLE` OK >The problem is if jobname contains a space. Then I might get: > >56~job name.pdf > >which is inconvenient. Job names may contain any number of >spaces, and this is especially a problem if it is a leading or trailing >space, as may not be evident when viewing a job list. jobtitle=$TEAJOBID~`basename $TEATITLE | tr -d ' '` or jobtitle=$TEAJOBID~`basename $TEATITLE | tr ' ' '_'` or some other printable character that wouldn't be confused. >I tried replacing any spaces by: > >jobname=${jobname// /-} > >Oddly, this works when I type it directly in a command shell, but does >NOT work when it executes as part of the script. Not enough details - shell, shebang line - something different about the environment. The newsgroup you are posting to 'comp.os.linux.help' is a "bogus" group not carried on that many news servers. You'd get better luck over in 'comp.unix.shell'. Have you tried there? Old guy