If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Unix Shell Scripts > Variable List

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 10-14-03, 16:04
Mike10 Mike10 is offline
Registered User
 
Join Date: Oct 2003
Posts: 7
Variable List

Anyone know how I can have a user enter a string and have that string removed from a variable list?

ie

list="One Two Three"
echo "Please enter string?"
read $string

...then get that string and remove it from the list someone..I was thinking using cut but I'm not sure. Please advise. Thanks.
Reply With Quote
  #2 (permalink)  
Old 10-16-03, 00:42
Mike10 Mike10 is offline
Registered User
 
Join Date: Oct 2003
Posts: 7
Bump

Any suggestions?
Reply With Quote
  #3 (permalink)  
Old 10-16-03, 13:04
fla5do fla5do is offline
Registered User
 
Join Date: Oct 2003
Location: Germany
Posts: 138
Hello Mike,

first : "read $string" is wrong better you take "read string"

second : the result from read command is not insert in "list". It is a seperate variable.

You can delete it by "$string=""". Where is the problem ?

Greetings from Germany
Peter F.
Reply With Quote
  #4 (permalink)  
Old 10-17-03, 01:16
Mike10 Mike10 is offline
Registered User
 
Join Date: Oct 2003
Posts: 7
string

Hi,

I want to have the user enter a string and have that string matched up against another variable in the script and 'removed'. Ie.

If the user enters 'Run' then it will match it against another variable in the script called Transporation="Walk Run Jog"

The new value of Transportation would be "Walk Jog"

Please advise. THanks in advance. Would 'awk' do the trick? not sure since I'm new at this.
Reply With Quote
  #5 (permalink)  
Old 10-17-03, 02:41
karthi_tvr karthi_tvr is offline
Registered User
 
Join Date: Oct 2003
Location: Singapore
Posts: 12
list="One Two Three"
echo "Please enter string?"
read string
new_string=""
for next in `echo $list | awk '{ for(i = 1; i <= NF; ++i) print $i}'`
do
if [ ! "$next" = "$string" ]; then
new_string=`echo $new_string $next`
fi
done
echo $new_string
__________________
Thanks and Regards
Karthik R
Reply With Quote
  #6 (permalink)  
Old 10-20-03, 14:44
Mike10 Mike10 is offline
Registered User
 
Join Date: Oct 2003
Posts: 7
Character

Hi..

I can't seem to get that character at the end of line 5? I tried double quotes instead but not working. I'm using korn shell. Any suggestions?
Reply With Quote
  #7 (permalink)  
Old 11-06-03, 12:46
Damian Ibbotson Damian Ibbotson is offline
Padawan
 
Join Date: Jun 2002
Location: UK
Posts: 525
Re: Character

Quote:
I can't seem to get that character at the end of line 5? I tried double quotes instead but not working. I'm using korn shell. Any suggestions?
That character is a backtick (`). On a UK keyboard at least, it is underneath the escape key, above tab. Commands between 2 backticks are substituted for their equivalent output and substituted into the current command. You could also use $(command).

[q]for next in `echo $list | awk '{ for(i = 1; i <= NF; ++i) print $i}'`[\q]

The line above is saying to echo the value of list, pipe this value into awk and then loop through each field passed into awk, print it out an dthen substitute the final value into the current command, i.e.

for next in outputFromEchoAwkCommand
do
...


A bit pointless really because this is effectively the same as...

for next in $list
do
...


A simpler example would be...

list="a b c d e f g h"
echo "Enter value: \c"; read value
for item in $list
do
[ $value != $item ] && newList="$newList $item"
done
list=$newList; echo $list

Or even...

list="a b c d e f g h"
echo "Enter value: \c"; read value
list=$(echo "$list" | sed "s/${value} \{1,\}//g"); echo $list

HTH
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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
Trackbacks are On
Pingbacks are On
Refbacks are On