bash hell , removing " and adding from a strings


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting bash hell , removing " and adding from a strings
# 1  
Old 06-28-2009
bash hell , removing " and adding from a strings

I'm writing a bash script and i'm stuck

the out put of a dialog menu is

echo $select
"foo" "bar" "lemon" cheese"

while I need
$foo $bar $lemon $cheese

to reuse them as strings later in the script
and very new to bash scripting and i've no idea how to do this
any help would be fantastic


<code>
dialog --backtitle "Enable / Disable Tags" \
--no-cancel --title "CHECKLIST BOX" \
--checklist "Hi, blah blah fill me in" 25 61 15 \
"$CITY" "$CITY_TAG" off \
"$COPYRIGHT" "$COPYRIGHT_TAG" off \
"$Orange" "$orange_tag" off \
"$Chicken" "$chicken_tag" off \
"$Cat" "$CAT_TAG" off\
"$Fish" "$FISH_TAG" off \
"$Lemon" "$LEMON_TAG" on 2> $tempfile2

retval=$?

enable=`cat $tempfile2`

echo $enable
</code>
"foo" "bar" "lemon" "poo-sticks"
# 2  
Old 06-29-2009
I'm not sure that I understand correctly what you're asking, but I think you are assigning a value that start with $ to a variable and want that value output. You will need to escape the character as \$value.

Here is an example:
Code:
foo=a
bar=b
dog=c

orange=\$foo
chicken=\$bar
cat=\$dog

echo "--------------"
enable="$orange $chicken $cat"
echo $enable

echo "--------------"
deref="$orange $chicken $cat"
eval echo $deref

echo "--------------"
alist="foo bar dog"
for var in $alist
do
    eval echo \$$var
    eval echo \$var
done

echo "--------------"
blist="orange chicken cat"
for var in $blist
do
    eval echo \$$var
    eval echo \$var
done

One other thing I am showing here is how to dereference a variable reference with eval.

Code:
$ ./mytest.sh 
--------------
$foo $bar $dog
--------------
a b c
--------------
a
foo
b
bar
c
dog
--------------
$foo
orange
$bar
chicken
$dog
cat

I hope this gives you an idea to solve your question.

-B
# 3  
Old 06-30-2009
i used that and and it still made no sense

but it all became clear after a good nights sleep
but thanks for the tips Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash script - Print an ascii file using specific font "Latin Modern Mono 12" "regular" "9"

Hello. System : opensuse leap 42.3 I have a bash script that build a text file. I would like the last command doing : print_cmd -o page-left=43 -o page-right=22 -o page-top=28 -o page-bottom=43 -o font=LatinModernMono12:regular:9 some_file.txt where : print_cmd ::= some printing... (1 Reply)
Discussion started by: jcdole
1 Replies

2. UNIX for Dummies Questions & Answers

"Help with bash script" - "License Server and Patch Updates"

Hi All, I'm completely new to bash scripting and still learning my way through albeit vey slowly. I need to know where to insert my server names', my ip address numbers through out the script alas to no avail. I'm also searching on how to save .sh (bash shell) script properly.... (25 Replies)
Discussion started by: profileuser
25 Replies

3. Shell Programming and Scripting

finding the strings beween 2 characters "/" & "/" in .txt file

Hi all. I have a .txt file that I need to sort it My file is like: 1- 88 chain0 MASTER (FF-TE) FFFF 1962510 /TCK T FD2TQHVTT1 /jtagc/jtag_instreg/updateinstr_reg_1 dff1 (TI,SO) 2- ... (10 Replies)
Discussion started by: Behrouzx77
10 Replies

4. Post Here to Contact Site Administrators and Moderators

Suggestion: adding two new groups "sed" and "awk"

Majority of the questions are pertaining file/string parsing w.r.t sed or awk It would be nice to have these two as their own sub category under shell-programming-scripting which can avoid lot of duplicate posts. (1 Reply)
Discussion started by: jville
1 Replies

5. Shell Programming and Scripting

Removing "^M" from the end of a String (i.e. "Ctrl+M")?

Hello All, I have an Expect script that ssh's to a remote server and runs some commands before exiting. One of the commands I run is the "hostname" Command. After I run this command I save the output using this line in the code below... Basically it executes the hostname command, then I... (2 Replies)
Discussion started by: mrm5102
2 Replies

6. AIX

Typing "bash" at the command line spawns two bash processes

Server: IBM p770 OS: AIX 6.1 TL5 SP1 When one of our develoeprs types "bash" on the command line to switch shells, it hangs. For some reason, two bash processes are created....the first bash process spawns a second bash process in the same console, causing a hang. Anyone have any idea what... (2 Replies)
Discussion started by: wjssj
2 Replies

7. Shell Programming and Scripting

removing the "\" and "\n" character using sed or tr

Hi All, I'm trying to write a ksh script to parse a file. When the "\" character is encountered, it should be removed and the next line should be concatenated with the current line. For example... this is a test line #1\ should be concatenated with line #2\ and line number 3 when this... (3 Replies)
Discussion started by: newbie_coder
3 Replies

8. Shell Programming and Scripting

Why generate "ash and bash" different output for same bash script?

Hi, For my bash script, terminal with bash is generate an OK output and program works right. already, terminal with ash have "line 48: syntax error: Bad substitution" output and program don't work. :confused: (0 Replies)
Discussion started by: s. murat
0 Replies

9. UNIX for Dummies Questions & Answers

get two strings ending with "." and starting with "."

Hi all, In unix shell, I want to get two strings ending with "." and starting with "." from a string "chan.txt" For example, a string "chan.txt". The first string is "chan" The second string is "txt" Yours Wilson (1 Reply)
Discussion started by: wilsonchan1000
1 Replies
Login or Register to Ask a Question