LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
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 03-11-2010, 05:17 PM   #1
eRJe
Member
 
Registered: May 2005
Location: Netherlands
Distribution: Slackware 14.1 Kernel 3.12.1
Posts: 103

Rep: Reputation: 16
setting IFS to ignore pattern


Hi there,

I'm working on a backup script which takes the following input:
Code:
RevBackup.sh <options> <source> <target>
The problem I'm having is that the source and target might contain spaces in the path. ie. /home/eRJe/My\ Documents

I would like the script to ignore "\ " (backslash-space) as being a delimiter. how could I do this without stopping a normal space from being a delimiter?

I was hoping I could do this with IFS. But so far I have only found info about setting a delimiter and not to "ignore" one

Thanks for any input!

Robbert
 
Old 03-11-2010, 06:00 PM   #2
tuxdev
Senior Member
 
Registered: Jul 2005
Distribution: Slackware
Posts: 2,012

Rep: Reputation: 115Reputation: 115
This is almost certainly due to not correctly quoting expansions, using $* instead of "$@", or other related issues. What is the script?
 
Old 03-12-2010, 03:29 AM   #3
eRJe
Member
 
Registered: May 2005
Location: Netherlands
Distribution: Slackware 14.1 Kernel 3.12.1
Posts: 103

Original Poster
Rep: Reputation: 16
Well this is the code I'm using for reading the arguments. I actually copied this part from another script because I liked the way it handles a varying No. of arguments as input.

Code:
# Reading arguments
unset IFS
for arg in $*; do
  ARGNAME="$(echo "$arg" |cut -d= -f1)"
  ARGVAL="$(echo "$arg" |cut -d= -f2)"
    
  if ! echo "$ARGNAME" |grep -q '^-'; then
    if [ -z "$SOURCE_PATH" ]; then
       SOURCE_PATH="$ARGVAL"
    else
       if [ -z "$TARGET_PATH" ]; then
          TARGET_PATH="$ARGVAL"
       else
          echo "Too many arguments"
          show_help;
          exit 1
       fi
    fi
 #
I wasn't aware of the $@. If I understood it well enough, changing the $* to "$@" should do the trick. I'll check it out when I'm back at home again.

Thanks for pointing me to this. I've been searching my ass off trying all sort of options with IFS, awk.

Robbert
 
Old 03-12-2010, 04:20 AM   #4
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,007

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191
Hi Robert

You might also want to look at getopts for parsing your options:

http://tldp.org/LDP/abs/html/internal.html#EX33
 
  


Reply



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
[SOLVED] Adding (not replacing) a pattern match with a similar pattern? b-bri Linux - Newbie 2 08-31-2009 12:36 AM
Procmail and IFS cipher7836 Linux - Newbie 2 08-05-2009 11:13 AM
printing pattern match and not whole line that matches pattern Avatar33 Programming 13 05-06-2009 06:17 AM
Ifs Gins Programming 2 07-18-2006 04:01 AM
setting IFS variable infamous41md Linux - Newbie 2 05-20-2003 06:12 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:16 PM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration