Embeded shell variable in command line


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Embeded shell variable in command line
# 1  
Old 05-03-2013
Embeded shell variable in command line

Hello,
I know this is a situation about the single quote and double literal, but I could not figure out after many search.

I need to loop through thousands of different BACs sequencing to optimize kmer individually.
Code:
IN=/PATH/TO/INPUT/FILES
for sample in S{01..1096}
do
     run_program in='$IN/${sample}_file1.fa $IN/${sample}_file2.fa' 
done

The package asks
Code:
in='input_file1 input_file2'

for the input files. Because of the single quote in the command option, the embedded shell variables cannot be interpreted literally. Is there a way to handle this situation?

Thanks a lot!

Yifang
# 2  
Old 05-03-2013
Code:
[user@host ~]$ x=2
[user@host ~]$ echo '$x'
$x
[user@host ~]$ echo "$x"
2
[user@host ~]$

HTH
# 3  
Old 05-03-2013
Yes, I am aware of the difference. The problem I met is the $x should be changed each loop, but the single quote of the command parameter escaped the $ sign of $x. Maybe I should ask like this:
Code:
MYVAR=sometext 
echo 'single quotes gives you $MYVAR'

Is there away to get output from the single quotes expression as the double quoted one? i.e.
Code:
echo 'single quotes gives you $MYVAR'
Output: 
single quotes gives you sometext

I cannot change the single quote as it has been set by the package. Thanks again!
# 4  
Old 05-03-2013
# 5  
Old 05-03-2013
Thanks!
The awk examples seems a possible way to what I want, but not exactly. It seems there is no way to change the single quote literal in bash for my case. I thought there could be a way to get what I want. Waiting for more ideas.
Thanks a lot in advance!
# 6  
Old 05-03-2013
Quote:
I cannot change the single quote as
it has been set by the package.
Well, what can you change? The easiest solution is:
Code:
run_program in="$IN/${sample}_file1.fa $IN/${sample}_file2.fa"

This User Gave Thanks to hanson44 For This Post:
# 7  
Old 05-03-2013
Ah, how simple it is!!! It works now.
Does this replacement apply to all the case IF there is embedded variable inside the single quote in general? I mean generally.
Thanks a lot again!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to read the output of a command line by line and pass it as a variable?

Hi, I have some 2000 names in a table like below. Java Oracle/SQL ANSI SQL SQL,DWH,DB DB&Java And by using for loop in my code i am able to get a single word but if there is any special character or space then it is considering as a next line. I have to execute the below queries in... (10 Replies)
Discussion started by: Samah
10 Replies

2. Shell Programming and Scripting

How to read a two files, line by line in UNIX script and how to assign shell variable to awk ..?

Input are file and file1 file contains store.bal product.bal category.bal admin.bal file1 contains flip.store.bal ::FFFF:BADC:CD28,::FFFF:558E:11C5,6,8,2,1,::FFFF:81C8:CA8B,::FFFF:BADC:CD28,1,0,0,0,::FFFF:81C8:11C5,2,1,0,0,::FFFF:81DC:3111,1,0,1,0 store.bal.... (2 Replies)
Discussion started by: veeruasu
2 Replies

3. Shell Programming and Scripting

Use shell variable in perl command line

Hi, I would like to use a shell variable $amp in my perl command line. for fa in $WORKSPACE/*.fa; do amp=`grep ">.*" $fa | sed -e's#>\(.*\)#\1#g'` ampsam="$WORKSPACE/$base/$base.$amp.sam" sqheader=`grep "^@SQ.*SN:$amp.*" $sam` printf "$sqheader\n" >> $ampsam ... (3 Replies)
Discussion started by: jdilts
3 Replies

4. Shell Programming and Scripting

SH script, variable built command fails, but works at command line

I am working with a sh script on a solaris 9 zone (sol 10 host) that grabs information to build the configuration command line. the variables Build64, SSLopt, CONFIGopt, and CC are populated in the script. the script includes CC=`which gcc` CONFIGopt=' --prefix=/ --exec-prefix=/usr... (8 Replies)
Discussion started by: oly_r
8 Replies

5. Shell Programming and Scripting

Not able to store command inside a shell variable, and run the variable

Hi, I am trying to do the following thing var='date' $var Above command substitutes date for and in turn runs the date command and i am getting the todays date value. I am trying to do the same thing as following, but facing some problems, unique_host_pro="sed -e ' /#/d'... (3 Replies)
Discussion started by: gvinayagam
3 Replies

6. Shell Programming and Scripting

Input variable in command line

i have this script that reads a file "listall_101111" where 101111 varies. awk '{print $0,$1}' listall_101111 | sed -e 's/\(.*\).$/\1/g' | awk '{print $6,$2,$3,$4,$5}' | sort -nrk5 | nawk 'NR==1{m=$5;a++;b=(b)?b:$0;next}$5==m{a++;b=(b)?b:$0}END{for (i in a){print b,a}}' | grep -v ^LG | sort... (4 Replies)
Discussion started by: aydj
4 Replies

7. UNIX for Dummies Questions & Answers

removing new line from the shell variable value

I have a small doubt that, how to chomp the new line from the bash shell variable value. In perl, i will do chomp, but how to do it in bash -- shell programming. When i redirect the date output i have a new line in it, which i would want to remove, how to do ?! (5 Replies)
Discussion started by: thegeek
5 Replies

8. Shell Programming and Scripting

Insert a line including Variable & Carriage Return / sed command as Variable

I want to instert Category:XXXXX into the 2. line something like this should work, but I have somewhere the wrong sytanx. something with the linebreak goes wrong: sed "2i\\${n}Category:$cat\n" Sample: Titel Blahh Blahh abllk sdhsd sjdhf Blahh Blah Blahh Blahh Should look like... (2 Replies)
Discussion started by: lowmaster
2 Replies

9. Shell Programming and Scripting

problem in embeded command substitution

$ echo $(tty|sed 's#/*/##') pts/0 $ who | grep $(tty|sed 's#/*/##') grep: 0652-033 Cannot open 0551-011. grep: 0652-033 Cannot open Standard. grep: 0652-033 Cannot open input. grep: 0652-033 Cannot open is. grep: 0652-033 Cannot open not. grep: 0652-033 Cannot open a. grep: 0652-033 Cannot... (2 Replies)
Discussion started by: wrl
2 Replies

10. Shell Programming and Scripting

Define an alias with an embeded awk command ??

Hi all, I'm trying to define an alias with an embeded awk command: alias kpipe='kill `psme| grep "ifw -r" | grep -v "grep ifw -r"| awk '{print $2}'`' The problem is that the awk command (awk '{print $2}') contains two ' ..' quotes. So bash assumes that the first awk quote corresponds to... (5 Replies)
Discussion started by: jfortes
5 Replies
Login or Register to Ask a Question