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 |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
 |
GNU/Linux Basic Guide
This 255-page guide will provide you with the keys to understand the philosophy of free software, teach you how to use and handle it, and give you the tools required to move easily in the world of GNU/Linux. Many users and administrators will be taking their first steps with this GNU/Linux Basic guide and it will show you how to approach and solve the problems you encounter.
Click Here to receive this Complete Guide absolutely free. |
|
 |
02-03-2004, 04:40 PM
|
#1
|
|
Member
Registered: Aug 2003
Posts: 234
Rep:
|
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?
|
|
|
|
02-03-2004, 04:46 PM
|
#2
|
|
Moderator
Registered: Feb 2001
Location: Atlanta, GA
Distribution: Slackware
Posts: 1,816
Rep: 
|
Code:
#!/bin/sh
HELLO='
'
echo "hello $HELLO there dude"
Code:
# . test.sh
hello
there dude
|
|
|
|
02-03-2004, 05:00 PM
|
#3
|
|
Member
Registered: Aug 2003
Posts: 234
Original Poster
Rep:
|
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
|
|
|
|
02-03-2004, 10:29 PM
|
#4
|
|
Member
Registered: Jan 2004
Location: Texas, USA, Terra
Distribution: Debian (currently...)
Posts: 74
Rep:
|
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... 
|
|
|
|
02-04-2004, 08:21 AM
|
#5
|
|
Member
Registered: Aug 2003
Posts: 234
Original Poster
Rep:
|
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.
|
|
|
|
02-04-2004, 10:01 AM
|
#6
|
|
Moderator
Registered: Feb 2001
Location: Atlanta, GA
Distribution: Slackware
Posts: 1,816
Rep: 
|
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"
|
|
|
|
02-04-2004, 10:30 AM
|
#7
|
|
Member
Registered: Aug 2003
Posts: 234
Original Poster
Rep:
|
sweet. now i under stand. thnx
|
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -5. The time now is 11:14 PM.
|
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|