Sponsored Content
Top Forums Shell Programming and Scripting how do i print literal value? Post 302596260 by knight_eon on Tuesday 7th of February 2012 04:12:43 AM
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

 

10 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

4. 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

5. 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

6. 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

7. 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

8. 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

9. 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

10. 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
lastcomm(8)						      System Manager's Manual						       lastcomm(8)

NAME
lastcomm - Outputs information about the last commands executed SYNOPSIS
lastcomm [Command] [Name] [Tty] DESCRIPTION
The lastcomm command outputs information about all previously executed commands that are recorded in the /var/adm/pacct file in reverse chronological order. You may specify a particular command with the Command parameter, a particular user with the Name parameter, and a particular terminal as the command source with the Tty parameter. Output is then restricted to the specified parameters. A Tty terminal may be named fully (for example, tty0) or abbreviated (for example, 0). The following information is displayed for each process: Name of the command under which the process was called. Any flags collected when the command was executed. The following flags are valid: Command was run with an effective user-id of 0. Command ran after a fork, but without an exec system call following it. Name of the user who issued the command. The terminal the command was started from. Seconds of CPU time used. Time the process started. EXAMPLES
To display information about all previously executed commands recorded in the /var/adm/pacct file, enter: lastcomm Information is displayed similar to: lastcomm ajh lat/620 1.13 secs Thu Feb 24 15:02 pg ajh lat/620 5.91 secs Thu Feb 24 15:01 ln miller ttyp1 1.14 secs Thu Feb 24 15:01 ls rob ttyp1 0.02 secs Thu Feb 24 15:01 pg sjz ttyp1 0.33 secs Thu Feb 24 15:00 sendmail SF root __ 0.01 secs Thu Feb 24 15:00 To display information about commands named a.out executed by the root user on terminal ttyd0, enter: lastcomm a.out root ttyd0 FILES
Specifies the command path. The current accounting file. RELATED INFORMATION
Commands: last(8) delim off lastcomm(8)
All times are GMT -4. The time now is 09:15 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy