Quick Variable Question


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Quick Variable Question
# 8  
Old 02-07-2006
Quote:
Originally Posted by vino
Did you try echo "$var1" ?
Thank you very much, appreciate it a lot. Yes, this did the trick, now it works. Smilie In fact, I don't even have to put "\n" when it's called like this.
# 9  
Old 02-07-2006
well in fact even while assigning the variable if you put a " instead of a ', the \n would have worked

eg, var="multi\n
line\n
variable"

echo $var
multi
line
variable
# 10  
Old 02-07-2006
Quote:
Originally Posted by linuxpenguin
well in fact even while assigning the variable if you put a " instead of a ', the \n would have worked

eg, var="multi\n
line\n
variable"

echo $var
multi
line
variable
No, it does not work for me. Tried it again just right now.
I get this:

echo $var
multi\n line\n variable
# 11  
Old 02-07-2006
From the bash man page:
Code:
     echo [-neE] [arg ...]
          Output the args, separated by  spaces,  followed  by  a
          newline.   The  return  status  is  always 0.  If -n is
          specified, the trailing newline is suppressed.  If  the
          -e  option  is  given,  interpretation of the following
          backslash-escaped characters is enabled.  The -E option
          disables the interpretation of these escape characters,
          even on systems where they are interpreted by  default.
          echo  does not interpret -- to mean the end of options.
          echo interprets the following escape sequences:
          \a   alert (bell)
          \b   backspace
          \c   suppress trailing newline
          \e   an escape character
          \f   form feed
          \n   new line
          \r   carriage return
          \t   horizontal tab
          \v   vertical tab
          \\   backslash
          \nnn the character whose ASCII code is the octal  value
               nnn (one to three digits)
          \xnnn
               the character whose ASCII code is the  hexadecimal
               value nnn (one to three digits)

Therefore:
Code:
 $ { AAA="a\nb\nc"; echo -e $AAA; }

produces:
Code:
a
b
c

And:
Code:
 $ { AAA="a\nb\nc"; echo $AAA; }

produces:
Code:
a\nb\nc

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Quick question on expanding variable

s=`awk '{ print $0}' /Applications/Relink.app/z_cloudline.txt` sed -n '"$s"' /var/mobile/Library/iFile/Bookmarks.plist > /var/mobile/originalip.txt What is the problem with that code ? With variable it only outputs: sed: -e expression #1, char 1: unknown command: `"' If I use the... (3 Replies)
Discussion started by: pasc
3 Replies

2. UNIX for Dummies Questions & Answers

Quick question.

I'd like to list all userid's on the system that have a .bashrc file in their home directory with a command like "cat /etc/passwd | grep -f", however I'm not quite familiar with using grep. Any suggestions? (2 Replies)
Discussion started by: raidkridley
2 Replies

3. Shell Programming and Scripting

quick question

I am using sed to find a pattern in a line and then I want to retain the pattern + the rest of the line. How is this possible? ie: line is: 14158 05-15-08 20:00 123-1234-A21/deliverable/dhm.a search for 123-1234-A21 ie: echo $line | sed 's/.*\(\{3\}-\{4\}-\{3\}\{5\}\).*/\1/' ... (1 Reply)
Discussion started by: phreezr
1 Replies

4. AIX

quick question

Hi, At best I'm a junior admin with a big problem. My developers have got my root password and mgmt insists they need it. I can't even change it when people knowing it leave. I'm certain they've hardcoded it into routines. I've searched my servers and grepped everything & can't find it. ... (5 Replies)
Discussion started by: keith.m
5 Replies

5. UNIX for Dummies Questions & Answers

Quick question

Hi, Is there a simple way, using ksh, to find the byte position in a file that a stated character appears? Many thanks Helen (2 Replies)
Discussion started by: Bab00shka
2 Replies

6. UNIX for Dummies Questions & Answers

Quick Question

Hi, I am new to UNIX, and am learning from this tutorial : http://www.ee.surrey.ac.uk/Teaching/Unix/index.html It keeps telling me to files downloaded from the internet (like .txt files) to the directory, and I dont know how to. How do I add .txt files to my directory? Thanks. (6 Replies)
Discussion started by: IAMTHEEVILBEAN
6 Replies

7. UNIX for Dummies Questions & Answers

Another quick question

Hi guys sed -e "s/$<//g" the $< can allow me to assign an input value to the variable right? do the double quotes check the previous context? (1 Reply)
Discussion started by: hamoudzz
1 Replies

8. UNIX for Dummies Questions & Answers

Quick Question

Hello There! I am trying to write this SIMPLE script in Bourne Shell but I keep on getting syntax errors. Can you see what I am doing wrong? I've done this before but I don't see the difference. I am simply trying to take the day of the week from our system and when the teachers sign on I want... (7 Replies)
Discussion started by: catbad
7 Replies

9. UNIX for Dummies Questions & Answers

A Quick Question

Wat is the difference between the cp mv ln etc in /usr/sbin/static and cp mv ln functions in /usr/bin (4 Replies)
Discussion started by: DPAI
4 Replies

10. UNIX for Dummies Questions & Answers

Quick Question

I know in DOS, when you want to pull up your last/previous command, you hit the up/down arrows. How do you do that with UNIX? (3 Replies)
Discussion started by: Tracy Hunt
3 Replies
Login or Register to Ask a Question