LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 11-03-2006, 01:49 AM   #1
primorec
Member
 
Registered: Sep 2004
Distribution: RH5.2/6.2/8.0/9.0,RHEL 3.0/4.X/5.X/6.X,MDK 10.1,KNOPPIX3.6,Solaris 8/9,CentOS 3.X/4.X/5.X/6.X/7.X
Posts: 67

Rep: Reputation: 15
scripting - using long variables


Hi All,


I want to load into the variable very long string (more than 80 characters) . For example:

#!/bin/tcsh
set VAR = "abcdefg qwertyuiop hjklgfdsaqwerttt etc etc etc etc ...."
echo $VAR


In order to make the script easier to read, I wold like to split the string into two lines. For example:

#!/bin/tcsh
set VAR = "abcdefg qwertyuiop \
hjklgfdsaqwerttt etc etc etc etc ...."
echo $VAR


It does not work.

Is there a way to accomplish this ?

Igor

P.S (Nov 5th 2006)

I've made a typo in the code snippets from above. Both $VAR should be quoted. In all my attempts on terminal, I've used "$VAR"... but when I've posted the question on LQ, I made a mistake. Sorry for the confusion

Summary:
echo "$VAR" does not work in second case
echo $VAR works in both cases

I've figured it out after reading case (4) on this link http://www.faqs.org/faqs/unix-faq/shell/csh-whynot/, posted by soggycornflake as post #5 bellow.

Last edited by primorec; 11-05-2006 at 02:55 PM.
 
Old 11-03-2006, 07:33 PM   #2
haertig
Senior Member
 
Registered: Nov 2004
Distribution: Debian, Ubuntu, LinuxMint, Slackware, SysrescueCD, Raspbian, Arch
Posts: 2,331

Rep: Reputation: 357Reputation: 357Reputation: 357Reputation: 357
Must be a shell thing. Both of your examples work for me perfectly under bash (but I left off the "set" - not needed under bash for your example). With or without the trailing backslashes.

I don't know about tcsh. I've never used that shell.
 
Old 11-05-2006, 08:06 AM   #3
konsolebox
Senior Member
 
Registered: Oct 2005
Distribution: Gentoo, Slackware, LFS
Posts: 2,248
Blog Entries: 8

Rep: Reputation: 235Reputation: 235Reputation: 235
perhaps you need to keep $VAR inside double quotes:

Code:
#!/bin/tcsh
set VAR = "abcdefg qwertyuiop \
hjklgfdsaqwerttt etc etc etc etc ...."
echo "$VAR"
 
Old 11-05-2006, 08:48 AM   #4
matthewg42
Senior Member
 
Registered: Oct 2003
Location: UK
Distribution: Kubuntu 12.10 (using awesome wm though)
Posts: 3,530

Rep: Reputation: 65
Personally I prefer the borne-like shells for scripting (bash & ksh being the ones I use the most). cshell and friends don't agree with me. You'll might get more mileage out of forums like this with borne-like shells since they are the default on many Linux distros. Having said that, choice is good.
 
Old 11-05-2006, 09:10 AM   #5
soggycornflake
Member
 
Registered: May 2006
Location: England
Distribution: Slackware 10.2, Slamd64
Posts: 249

Rep: Reputation: 31
csh is fine for interactive use but it's a bad idea to script with it. Read this.

I don't think you can do what you want with csh (see section 4 of that link).
 
  


Reply



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
moving files that have spaces in variables -bash scripting bhar0761 Programming 10 09-22-2005 07:30 AM
server variables in bash scripting basher400 Linux - Newbie 4 04-11-2005 06:04 AM
Scripting : Dual line output into next script as variables facets Programming 6 06-10-2004 02:28 PM
bash scripting - how long ago file was modified brian0918 Programming 3 06-19-2003 04:10 PM
Shel scripting: variables pointing to variables and case Dark_Helmet Programming 5 06-08-2003 11:07 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 06:31 PM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration