Unable to store "-e" in variable ??????


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Unable to store "-e" in variable ??????
# 1  
Old 08-13-2010
Error Unable to store "-e" in variable ??????

p="-e"
echo $p

It is not returning the value "-e" stored. Instead returns null.

I am wondering how could this happen. Please help me out.I tried all possibilities like p='-e' | p="\-e". Nothing seems to work.

SmilieSmilie
# 2  
Old 08-13-2010
echo assumes the -e is a commandline parameter(echo does indeed take -e on some systems, see man echo) and uses it instead of echoing it. To tell echo that the following string contains no parameters, tell it echo --.

Code:
STR="-e"
echo -- "$STR"

This User Gave Thanks to Corona688 For This Post:
# 3  
Old 08-13-2010
Thanks corona. It works, but still

echo -- $str ==> -- -e

Is it posible to give just teh stored value "-e" or so we need to cut and get the variable.?

---------- Post updated at 04:47 PM ---------- Previous update was at 04:29 PM ----------

I finally settled for :

str="-e"

echo .$str | sed 's/\.//1'

-e

So wherever I want to echo variables (even if it contains -e/-n/-E ) I used the above & it works fine. Thanks corona !! Smilie
# 4  
Old 08-13-2010
Code:
printf %s\\n "$p"

This User Gave Thanks to alister For This Post:
# 5  
Old 08-13-2010
Cool.. Wat %s mean? and will it be issue to use printf in ksh?
# 6  
Old 08-13-2010
"%s" means "substitute a string". See man printf. printf is an external command that should be present for any shell.
# 7  
Old 08-13-2010
Corona,

I need assistance on another issue too.
I want a variable to be left indented with fixed size.

With "typeset -Z100 temp" am able to get fixed size variable, but it is rigt indented.
Any Idea to get left indented?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 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

Using "mailx" command to read "to" and "cc" email addreses from input file

How to use "mailx" command to do e-mail reading the input file containing email address, where column 1 has name and column 2 containing “To” e-mail address and column 3 contains “cc” e-mail address to include with same email. Sample input file, email.txt Below is an sample code where... (2 Replies)
Discussion started by: asjaiswal
2 Replies

3. Shell Programming and Scripting

Unable to store "python --version" to a shell variable

Hi All, I need to get the version of python installed and store it in a variable for later use. Whereas it is printing on the console instead of storing to variable. I am able to store output of ls command in a variable. Please check the below code : root@myhost:/volumes/srini# cat... (4 Replies)
Discussion started by: srinivasan.neel
4 Replies

4. Solaris

Netra X1 LOM: Unable to change any variable via the "set" command

I'm posting here as it didn't seem quite right in the hardware section (as it's LOM commands). My apologies if I have that wrong though :) I've finally gotten round to configuring the LOM on my Netra X1, but I can't get it to change the hostname via the "set" command: lom>show hostname... (2 Replies)
Discussion started by: Smiling Dragon
2 Replies

5. Shell Programming and Scripting

awk command to replace ";" with "|" and ""|" at diferent places in line of file

Hi, I have line in input file as below: 3G_CENTRAL;INDONESIA_(M)_TELKOMSEL;SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL My expected output for line in the file must be : "1-Radon1-cMOC_deg"|"LDIndex"|"3G_CENTRAL|INDONESIA_(M)_TELKOMSEL"|LAST|"SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL" Can someone... (7 Replies)
Discussion started by: shis100
7 Replies

6. Shell Programming and Scripting

Store Host lookup in variable ("on the fly")

Hi, I'm new here. I was wondering why I can't store a host lookup in a variable. for line in $(< blacklist) do STOREIP=host $line; if ]; then $line >> blacklist2; else $line >> blacklist3; fi done Result: "ip" command not found .. so how would I store the host lookup in the... (2 Replies)
Discussion started by: sOliver
2 Replies

7. Shell Programming and Scripting

store the output of "find" command in a variable?

I intend to find the path/full location of a file(filename given by user thru "read filenme") using "find" or any other command and then store it's output in a variable for some other processing. But struggling to put all things together (i.e finding the fully qualified location of that file and... (4 Replies)
Discussion started by: punitpa
4 Replies

8. Shell Programming and Scripting

How to store the output of "time dd if= of=" in a variable

Hi All, I need to store the real seconds of the following command in a variable. How could it be done? time $(dd if=/dev/zero of=/dev/sda1 bs=512 count=2048;sync) Thanks, Amio (12 Replies)
Discussion started by: amio
12 Replies

9. SuSE

VMDB Failure" followed by "Unable to open snapshot file"

keep getting an error when I try to revert to a snapshot: "VMDB Failure" followed by "Unable to open snapshot file" Im using vmware server 1.0.4, host OS is windows xp and guest OS is SLES. Is there anything I can do to recover the snapshot or am I in trouble!?!?! (0 Replies)
Discussion started by: s_linux
0 Replies

10. Programming

getting "mi_cmd_var_create: unable to create variable object" error msg

Hi, i am working in C in Fedora Eclipse 3.3.0 with gdb debugger. I am geting segmentation fault with an error message "mi_cmd_var_create: unable to create variable object" on debugging the program. What should I do to solve this problem? rgds, Dona_m (14 Replies)
Discussion started by: dona_m
14 Replies
Login or Register to Ask a Question