how do i print literal value?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting how do i print literal value?
# 1  
Old 02-06-2012
how do i print literal value?

hi guys!!!
i wanna print literal value itself.
for example,
mycommand=$( ls -ltr )
"echo $mycommand" is not working... it runs the "ls" command.
also "echo $"mycommand" " is not working either. it print out "mycommand" literally...
how can i print out " ls -ltr " using variable "mycommand"?
# 2  
Old 02-07-2012
Did you search the forum?
Code:
x='ls -lrt'

This User Gave Thanks to balajesuri For This Post:
# 3  
Old 02-07-2012
yeah i searched, but couldnt find any.
it works!!! thank you!!!
but i want to set variable like x=$(l -ltr) and print value as string, can you do that?

Last edited by curtis911; 02-07-2012 at 04:41 AM..
# 4  
Old 02-07-2012
Anything in single-quotes will be considered literally.

Is this what you mean:
Code:
> x='$(ls -lrt)'
> echo $x
$(ls -lrt)

# 5  
Old 02-07-2012
Sorry, but unable to understand what you need?

Here are some conclusions in codes:

Code:
# x=$(ls -ltr)
# echo "$x"
total 20
-rw-r--r--  1 root root 58 Feb  7 12:29 data
-rw-r--r--  1 root root  0 Feb  7 13:51 script.sh
-rw-r--r--  1 root root  0 Feb  7 13:51 eon
-rw-r--r--  1 root root  0 Feb  7 13:51 bin.sh

# echo ${x}
total 20 -rw-r--r-- 1 root root 58 Feb 7 12:29 data -rw-r--r-- 1 root root 0 Feb 7 13:51 script.sh -rw-r--r-- 1 root root 0 Feb 7 13:51 eon -rw-r--r-- 1 root root 0 Feb 7 13:51 bin.sh

# x='ls -ltr'
# echo $x
ls -ltr
# echo "$x"
ls -ltr
# $x
total 20
-rw-r--r--  1 root root 58 Feb  7 12:29 data
-rw-r--r--  1 root root  0 Feb  7 13:51 script.sh
-rw-r--r--  1 root root  0 Feb  7 13:51 eon
-rw-r--r--  1 root root  0 Feb  7 13:51 bin.sh

---------- Post updated at 02:42 PM ---------- Previous update was at 02:38 PM ----------

Quote:
Originally Posted by curtis911
yeah i searched, but couldnt find any.
it works!!! thank you!!!
but i want to set variable like x=$(l -ltr) and print value as string, can you do that?
x=$(ls -ltr) : Through this construct, we pass the output of the command inside $() to the variable x. U can not pass the literal string via $() construct.

Or you can do one thing:

x=$(echo ls -ltr)

Code:
# x=$(echo ls -ltr)
# echo $x
ls -ltr
# $x
total 20
-rw-r--r--  1 root root 58 Feb  7 12:29 data
-rw-r--r--  1 root root  0 Feb  7 13:51 script.sh
-rw-r--r--  1 root root  0 Feb  7 13:51 eon
-rw-r--r--  1 root root  0 Feb  7 13:51 bin.sh

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Passing literal tab character from zsh to other program

I have a Zsh script which invokes another program. One of the paramters to be passed, should be a literal tab, i.e what in common programming languages is often written as "\t". If it were bash, I think I could use the special form $"\t" but this doesn't seem to work (the called program... (5 Replies)
Discussion started by: rovf
5 Replies

2. UNIX for Beginners Questions & Answers

How bash treats literal date value and retrieve year, month and date?

Hi, I am trying to add few (say 3 days) to sysdate using - date -d '+ 3 days' +%y%m%d and it works as expected. But how to add few (say 3 days) to a literal date value and how bash treats a literal value as a date. Can we say just like in ORACLE TO_DATE that my given literal date value... (2 Replies)
Discussion started by: pointers1234
2 Replies

3. UNIX for Beginners Questions & Answers

Fgrep literal string from a file

have a file1 aaa-bbb-ccc-abcd aaa-bbb-ccc-bacd aaa-bbb-ccc-aaad aaa-bbb-ccc-ahave another file2 aaa-bbb-ccc-a fileusing the fgrep command, trying to have only the literal string returned. fgrep -f file2 file1 is returning aaa-bbb-ccc-abcd aaa-bbb-ccc-aaad aaa-bbb-ccc-aOnly looking for... (1 Reply)
Discussion started by: jimmyf
1 Replies

4. Shell Programming and Scripting

Difficulties in matching left bracket as literal in awk

I need to work with records having #AX in the EXP1 , please see my data sample and my attempt below: $ cat xx 08:30:33 KEY1 (1255) EXP1 VAL:20AX0030006 08:30:33 KEY1 (1255) EXP1 VAL:20AX0030006 08:30:33 KEY1 (1255) EXP1 VAL:20AW0030006 08:30:33 KEY1 (1255) EXP1 VAL:20AW0030006 $ gawk '{... (1 Reply)
Discussion started by: migurus
1 Replies

5. Shell Programming and Scripting

Reading a long literal continued next line

I am trying to identify all messages or prompts from a number of COBOL programs and they can usually be identified by a pair of double quotes on one line. However, sometimes the literal will not be finished on the first line but after a dash in column 7 of the next line, the literal will be... (6 Replies)
Discussion started by: wbport
6 Replies

6. Shell Programming and Scripting

Fgrep/grep -f and literal strings

I have a file like this: cat file name = server jobname = 1010 snapshot_name = funky_Win2k12_20140213210409 I'm trying to use grep to isolate that first line (name = server), but grep -f "name = " file as well as fgrep "name = " file returns all 3 lines. How do I return... (1 Reply)
Discussion started by: ampsys
1 Replies

7. Shell Programming and Scripting

Cannot get literal ampersand to display in SQL output

Gurus, Thanks so much for your help, in advance. I'm using ksh and outputting a literal string value to an output file, however, Unix isn't playing by SQL's rules. The ampersand character which I'm trying to disply as a knowledge base link is screwing up the output. Typically, the "&&" is... (1 Reply)
Discussion started by: WhoDatWhoDer
1 Replies

8. UNIX for Dummies Questions & Answers

sed containing $ as literal and variable

Hi, i have a data file cat f1.txt $V01$S this is 1 $v02$D this is 2 $v03$F this is 3 I have a variable $PARM which contains value say 'V01' I have to print lines from f1.txt that start with '$'<${PARM}>'$' How do i get matching lines from f1.txt that start with '$' then with ${PARM}... (1 Reply)
Discussion started by: ysrini
1 Replies

9. Shell Programming and Scripting

Bash: Reading out rows of a file into a dynamic array and check first literal

Hello, i have a file "Movie.ini" looking e.g. like follows * MOVIE A bla bla MOVIE B blubb blubb MOVIE C I'd like to read the file "Movie.ini" with cat and grep and check whether it includes the string MOVIE only with a '*' at the beginnig. By doing "cat Movie.ini| grep MOVIE... (14 Replies)
Discussion started by: ABE2202
14 Replies

10. Shell Programming and Scripting

How to scan a file for literal, return 0 or 1 if found?

How can i scan a file in a UNIX script and look for a particular keyword? For example if i wanted to scan the file "lpcmp165.out" and see if it contains the term "error" or "ERROR" and then return a 0 or 1 or some indicator as such? Detail example: sqlplus -s xx/yyyyyyy#@zzz <<EOF >... (11 Replies)
Discussion started by: bobk544
11 Replies
Login or Register to Ask a Question