how to use ` inside a `


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers how to use ` inside a `
# 1  
Old 12-04-2011
how to use ` inside a `

For example, as of now i am doing in 2 lines:

Code:
a=`cat $1|wc -l`
b=`expr $a  - 1`

How i can above into single line?
Code:
b=`expr `cat $1|wc -l` - 1`

The above code doesn't work.
why i am not able to use multiple `s in single line.
Whats the alternative for this?
Thanks
# 2  
Old 12-04-2011
You need to escape the inner ` (like \`).

If you use the $(...) syntax for command substitution, you don't need to escape anything.

Code:
b=$(($(wc -l < $1) - 1))

This User Gave Thanks to Scott For This Post:
# 3  
Old 12-04-2011
Thanks man!
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

If inside If loop

Hi All, Below is the very simple code snippet but it si giving me syntax error #!/bin/bash #To ensure If JMS directory exists or not ServerName=$(hostname) #To ensure If JMS directory exists or not echo $ServerName if ; then echo "Inside First If" if ; then echo 'JMS... (4 Replies)
Discussion started by: sharsour
4 Replies

2. Shell Programming and Scripting

Renumber position 88-94 inside all files matching criteria inside folder

There are 4 files inside one folder matching criteria i.e. File name = ABCJmdmfbsjopXXXXXXX_mm-dd-yyyy_XXX.data Here is the Code which find the files matching criteria:- TS=`date +"%m-%d-%Y"`| for fname in `find . -name "ABCJmdmfbsjop???????_${TS}*.data"` do # Matching File Processing Code.... (1 Reply)
Discussion started by: lancesunny
1 Replies

3. Shell Programming and Scripting

Using 'su' inside a loop

Hi, I am using su within a for loop. As you might expect, it prompts for password during each loop execution. Here is my piece of code: for i in $LIST do if then DATABASE=`echo $i | awk -F "|" '{ print $1 }'` USER_ID=`echo $i | awk -F "|" '{ print $2 }'` su - apstage -c... (1 Reply)
Discussion started by: sugan
1 Replies

4. Shell Programming and Scripting

variable inside variable inside loop headache

Hi Gurus I have a file called /tmp/CMDB which looks like this serial: 0623AN1208 hostname: server1 model: x4100 assetID: 1234 I am writing a for loop that will go through this file line by line creating a variable of itself. Using the first iteration of the loop (i.e. the first line) as... (6 Replies)
Discussion started by: hcclnoodles
6 Replies

5. Shell Programming and Scripting

If condition inside while???

Hi source is text file named alpha.text containing entries ABC DEF XYZ YYY BBB I need a small shell script which should do read the entries in alpha.text one by one and check it with the current date. If the date is Mon (monday) and entry read from the file is 'DEF' then this should... (4 Replies)
Discussion started by: PrasannaKS
4 Replies

6. Shell Programming and Scripting

value inside a function

i have a script like this #!/bin/ksh initialize() { x=20 } ... ... ... x=10 initialize; echo $x (2 Replies)
Discussion started by: trichyselva
2 Replies

7. Programming

do-while inside switch

Hi All, Could anybody please explain to me, why this piece of code compiles. void duff(register char *to, register char *from, register int count) { register int n=(count+7)/8; switch(count%8){ case 0: do{ *to++ = *from++; case 7: *to++ = *from++; case... (2 Replies)
Discussion started by: lagigliaivan
2 Replies

8. Shell Programming and Scripting

Problem inside 'if'

Hi, I am using a test inside an if loop like below if then ..........do something... However, when I am running the script by sh -x <script_name>, I am getting an error like test.sh: test: unknown operator -. Both the variables current_min and timestamp_min are numeric. Many thanks (1 Reply)
Discussion started by: ayankm
1 Replies

9. Shell Programming and Scripting

looping a array inside inside ssh is not working, pls help

set -A arr a1 a2 a3 a4 # START ssh -xq $Server1 -l $Username /usr/bin/ksh <<-EOS integer j=0 for loop in ${arr} do printf "array - ${arr}\n" (( j = j + 1 )) j=`expr j+1` done EOS # END ========= this is not giving me correct output. I... (5 Replies)
Discussion started by: reldb
5 Replies

10. Programming

pipes inside

Extremely need to understand some aspects of pipes realization. The main question is in which memory are pipes placed? (13 Replies)
Discussion started by: pranki
13 Replies
Login or Register to Ask a Question