LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 11-26-2007, 04:05 PM   #1
reverse
Member
 
Registered: Apr 2007
Distribution: Gentoo
Posts: 337

Rep: Reputation: 30
Bash command separator/arguments separator


Is there a simple way to force BASH *not* to use the ";" character as shown below:

Code:
$ command_1 ; command_2 ; ... ; command_n
but rather a user-specified character, for example the character.. erh.. ! (or something, whatever):

Code:
$ command_1 ! command_2 ! ... ! command_n
Perhaps an environment variable, or similar?

Alas, should you want to pass a space-infested string as the first argument to a program, a construction of the following sort has to be used:

Code:
$ program "this is argv1"
I need to know if, yet again, the quote character can be replaced with something else, such as.. I'll just take ! again:

Code:
$ program !this is argv1!
 
Old 11-26-2007, 04:18 PM   #2
rsashok
Member
 
Registered: Nov 2006
Location: USA, CA
Distribution: RedHat, Debian
Posts: 202

Rep: Reputation: 31
No, you can't replace double quote with anything else.
 
Old 11-27-2007, 01:00 AM   #3
gnashley
Amigo developer
 
Registered: Dec 2003
Location: Germany
Distribution: Slackware
Posts: 4,756

Rep: Reputation: 466Reputation: 466Reputation: 466Reputation: 466Reputation: 466
You can't easily replace the quotes, but the separator character can be chaged with the 'IFS' variable (Internal File Separator). The standard setting for this is equivalent to 'space,tab,end-of-line'. Usually, if you are going to change it in a script you save the original value so it can be restored for normal use in other loops, so you atrt by putting:
OLDIFS=$IFS
IFS='whatever separator'

code....

IFS=$OLDIFS

Last edited by gnashley; 11-27-2007 at 01:08 AM.
 
Old 11-27-2007, 01:21 AM   #4
chrism01
Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.5, Centos 5.10
Posts: 16,269

Rep: Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028
I don't think you can replace ';', that's not part of IFS, it's a cmd separator, different concept.

IFS: http://dict.die.net/ifs/
 
Old 11-28-2007, 03:36 PM   #5
reverse
Member
 
Registered: Apr 2007
Distribution: Gentoo
Posts: 337

Original Poster
Rep: Reputation: 30
Hello. Sorry, I was *actually* looking for the variable that contains the character(s) that separates arguments passed to a program. I understand this is IFS, however, I do not understand why this does not work:

Code:
$ IFS=:
$ echo "${IFS}"
:
$ /bin/ls a.txt:b.txt
/bin/ls: a.txt:b.txt: No such file or directory
$ /bin/ls a.txt b.txt
a.txt b.txt
$
So obviously, although the 2nd and 3rd lines show that IFS is supposed to be set to ":", the command given on the 4th line (1st LS) does not work. I would expect this to work:

Code:
$ IFS=:
$ /bin/ls:file1:file2:file3

Last edited by reverse; 11-28-2007 at 03:38 PM.
 
Old 11-28-2007, 03:59 PM   #6
rsashok
Member
 
Registered: Nov 2006
Location: USA, CA
Distribution: RedHat, Debian
Posts: 202

Rep: Reputation: 31
Try following:
Code:
$bash -c 'IFS=":"; files="a.txt:b.txt"; ls -l $files'
It worked for me.

Last edited by rsashok; 11-28-2007 at 04:01 PM.
 
Old 11-28-2007, 04:52 PM   #7
makyo
Member
 
Registered: Aug 2006
Location: Saint Paul, MN, USA
Distribution: {Free,Open}BSD, CentOS, Debian, Fedora, Solaris, SuSE
Posts: 718

Rep: Reputation: 72
Hi.

From the O'Reilly book:
Quote:
Command-Line Processing

1. Splits the command into tokens that are separated by the fixed
of set metacharacters: SPACE, TAB, NEWLINE, ;, (, ), <, >, |, and &.

9. Takes the parts of the line that results from parameter,
command, and arithmetic substitution and splits them into words
again, This time it uses the characters in $IFS as delimiters
instead of the set of metacharacters in Step 1.

-- Learning the bash Shell, 2nd, pages 177 - 179.
Best wishes ... cheers, makyo

Last edited by makyo; 11-28-2007 at 04:54 PM.
 
Old 12-01-2007, 10:38 AM   #8
ta0kira
Senior Member
 
Registered: Sep 2004
Distribution: FreeBSD 9.1, Kubuntu 12.10
Posts: 3,078

Rep: Reputation: Disabled
Maybe you can somehow wrap the command lines with sed? I'm not sure how you'd do that, but it sounds entirely plausible. I don't know if it could be done transparently unless you created a wrapper program which created a vterm and passed everything along to the "real" term while filtering typed input.
ta0kira
 
Old 12-01-2007, 05:05 PM   #9
makyo
Member
 
Registered: Aug 2006
Location: Saint Paul, MN, USA
Distribution: {Free,Open}BSD, CentOS, Debian, Fedora, Solaris, SuSE
Posts: 718

Rep: Reputation: 72
Hi.
Quote:
Originally Posted by ta0kira View Post
Maybe you can somehow wrap the command lines with sed ...
I don't see the problem as anything except not being able to use IFS on literal strings.

To parse a string, assign it to a variable, set IFS, and use the results. Reset IFS afterwards as necessary. The example from rsashok illustrates this.

Or am I missing something? ... cheers, makyo

Last edited by makyo; 12-01-2007 at 05:07 PM.
 
Old 12-01-2007, 06:19 PM   #10
chrism01
Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.5, Centos 5.10
Posts: 16,269

Rep: Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028
You prob need to use single quotes around it, to avoid it being used as the bash built-in do-nothing/null cmd:
Code:
:          [builtin] - do nothing; this builtin has no effect

http://www.linspireguide.com/LinspireCommands2
If used, it's usually in an if block where it's clearer to say if "[[ sometest ]] do nothing else... fi" rather than try to reverse the logic.
eg
Code:
if [[ complextest ]]
then
    # this line does 'nothing ie a null cmd like x=x
    :
else
    do something
fi
 
Old 12-02-2007, 05:51 AM   #11
reverse
Member
 
Registered: Apr 2007
Distribution: Gentoo
Posts: 337

Original Poster
Rep: Reputation: 30
Hello. Perhaps some (most/all?) of the people who read the thread are wondering about why I care about IFS. I /care/ about it because I am trying to understand why the system() function is considered insecure (according to its manual page). See this thread for a few details: http://www.linuxquestions.org/questi...secure-603187/
 
Old 12-02-2007, 09:21 PM   #12
chrism01
Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.5, Centos 5.10
Posts: 16,269

Rep: Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028
See my answer there....
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
My field separator changes when using awk Helene Programming 3 05-01-2004 08:10 AM
make separator error robw Linux - Software 1 12-07-2003 03:08 PM
make separator error robw Linux - Newbie 0 12-06-2003 02:49 PM
Makefile separator problem Ownasaurus Linux - Software 5 09-07-2003 01:07 PM
Missing Separator? jamespetts Linux - Software 2 09-05-2002 12:24 PM


All times are GMT -5. The time now is 06:00 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration