LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
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 06-04-2007, 05:42 PM   #1
Sushy
Member
 
Registered: Sep 2005
Distribution: FreeBSD
Posts: 84

Rep: Reputation: 15
bash syntax


I have simple bash script:
Code:
#!/usr/local/bin/bash
NAME=abc
IP=1.2.3.4
IFACE=eth0
echo "
# $NAME
test_$NAME_rootdir="/directory/$NAME"          # comment1
test_$NAME_hostname="$NAME.example.com"        # comment2
test_$NAME_ip="$IP"                           # comment3
test_$NAME_interface="$IFACE"                 # comment4
" > /test
I know, that something, somewhere is not correct with syntax, cos I have this output:
Code:
# abc
test_=/directory/abc          # comment1
test_=abc.example.com        # comment2
test_=1.2.3.4                           # comment3
test_=eth0                 # comment4
But I need:
Code:
# abc
test_abc_rootdir="/directory/abc"          # comment1
test_abc_hostname="abc.example.com"        # comment2
test_abc_ip="1.2.3.4"                      # comment3
test_abc_interface="eth0"                   # comment4
Enclosing characters in single quotes ' preserves the literal value of each character within the quote, so no $ possible, so this is I don`t need.
Enclosing characters in double quotes " preserves the literal value of all characters within the quotes, with the exception of `$',
so this is what I need, but anyway still some faults in output with _ and ""

Last edited by Sushy; 06-04-2007 at 05:46 PM.
 
Old 06-04-2007, 06:25 PM   #2
ilikejam
Senior Member
 
Registered: Aug 2003
Location: Glasgow
Distribution: Fedora / Solaris
Posts: 3,109

Rep: Reputation: 97
Hi.

Try:
Code:
#!/usr/local/bin/bash
NAME=abc
IP=1.2.3.4
IFACE=eth0
echo "
# $NAME
eval test_${NAME}_rootdir="/directory/$NAME"          # comment1
eval test_${NAME}_hostname="$NAME.example.com"        # comment2
eval test_${NAME}_ip="$IP"                           # comment3
eval test_${NAME}_interface="$IFACE"                 # comment4
" > /test
Also, you might want to escape the '"'s inside the echo.

Dave

Last edited by ilikejam; 06-04-2007 at 06:28 PM.
 
  


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
bash-3.1 bug or syntax error? moszern Linux - Software 1 06-12-2006 12:57 PM
BASH : syntax error semaja2 Programming 6 01-26-2006 12:33 AM
explanation on some bash syntax slzckboy Programming 2 10-02-2005 06:06 AM
Bash For Loops gives syntax error meadensi Linux - Newbie 2 02-23-2005 10:30 AM
help with basic syntax in bash script Supp0rtLinux Linux - Software 4 03-27-2003 06:57 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:11 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