LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 02-03-2004, 04:40 PM   #1
wedgeworth
Member
 
Registered: Aug 2003
Posts: 234

Rep: Reputation: 30
simple scripting question


is there anyway to assign a carriage return to a variable? just i regular bash scripting.

space="\n"

just ends up printing \n in the middle of the text instead of seperating it with a carriage return.

any help?
 
Old 02-03-2004, 04:46 PM   #2
crabboy
Moderator
 
Registered: Feb 2001
Location: Atlanta, GA
Distribution: Slackware
Posts: 1,823

Rep: Reputation: 120Reputation: 120
Code:
#!/bin/sh

HELLO='
'

echo "hello $HELLO there dude"
Code:
# . test.sh
hello 
 there dude
 
Old 02-03-2004, 05:00 PM   #3
wedgeworth
Member
 
Registered: Aug 2003
Posts: 234

Original Poster
Rep: Reputation: 30
i think i tried that. or atleast something like that. anyway, i tried it like you did just to see. it works for the print out like that put when i use it in my array....which is what i've been testing most of this on before i turned here.... it didn't work. you can see the exact same variable is used for your test and mine. it works on yours but not mine. it just enters a space. not a return. why?

//***************************************\


#!/bin/bash

hi="hi"
space=" "
#space2="******"
space2='

'
goodbye="goodbye"
i=0
HELLO='
'

#Spare out entries into array
#priming read
array3[0]=${hi}$HELLO${goodbye}
echo ${array3[i]}
#echo $i


echo "hello $HELLO there dude"



//***************************************\
# ./carriage_return.sh
hi goodbye
hello
there dude
 
Old 02-03-2004, 10:29 PM   #4
maillion
Member
 
Registered: Jan 2004
Location: Texas, USA, Terra
Distribution: Debian (currently...)
Posts: 74

Rep: Reputation: 15
The echo command in bash will allow you to enter a newline or carriage return by using \n and \r respectively. You may have to use "echo -e \n" or "echo -e \r" (without the quotes). The -e is supposed to allow echo to use these 'special characters'. Try it both ways to learn...
 
Old 02-04-2004, 08:21 AM   #5
wedgeworth
Member
 
Registered: Aug 2003
Posts: 234

Original Poster
Rep: Reputation: 30
maillion...i understand that. the problem is assigning that value into the middle of an array of characters. that's the problem. see the code above for what i'm trying to do. i want to be able to assign a carriage return between "hi" and "goodbye" in the array3[0] array.....sorry if i'm missunderstanding. i just wanted you to know what i was trying to do.
 
Old 02-04-2004, 10:01 AM   #6
crabboy
Moderator
 
Registered: Feb 2001
Location: Atlanta, GA
Distribution: Slackware
Posts: 1,823

Rep: Reputation: 120Reputation: 120
Using the -e with echo works.
Code:
#!/bin/bash

hi="hi"
space=" "
#space2="******"
space2='

'
goodbye="goodbye"
i=0
HELLO='\n'

#Spare out entries into array
#priming read
array3[0]=${hi}${HELLO}${goodbye}
echo -e ${array3[i]}
#echo $i


echo -e "hello $HELLO there dude"
 
Old 02-04-2004, 10:30 AM   #7
wedgeworth
Member
 
Registered: Aug 2003
Posts: 234

Original Poster
Rep: Reputation: 30
sweet. now i under stand. thnx
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Very simple BASH scripting question clickster Linux - Newbie 6 11-23-2005 04:28 PM
Simple Shell Scripting Question hellomynameisphil Programming 2 08-27-2005 03:41 AM
Simple bash/awk/sed scripting question R00ts Programming 4 04-16-2005 02:55 AM
Bash Scripting--Simple Question mooreted Linux - General 4 05-10-2004 01:44 PM
Simple scripting question - running a command for a specified time FluoroAlien Programming 8 03-06-2004 12:33 AM


All times are GMT -5. The time now is 03:46 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration