You are not logged in.

#1 2007-01-17 03:06:47

arew264
Member
From: Friendswood, Texas, US
Registered: 2006-07-01
Posts: 394
Website

Shell Script Refuses to Cooperate

I'm trying to make shell script that uses the address of eth0 as a variable, and to that end I have created a command called eth0addr that simply echoes the ip address of eth0 to you. The problem is that every how to for shell scripting I have read says I should set the variable like this:
EXTIP='eth0addr'

To get the result of that command. The issue is that when I actually echo it:
echo $EXTIP
'eth0addr'

The script isn't getting the result of the command, it's treating the command as a string. How do I get this to work?

Offline

#2 2007-01-17 03:33:57

Dusty
Schwag Merchant
From: Medicine Hat, Alberta, Canada
Registered: 2004-01-18
Posts: 5,986
Website

Re: Shell Script Refuses to Cooperate

the scripts are telling you to use backticks, the ones under the ~ sign on your keyboard, not single quotes. You can also use EXTIP=$(eth0addr), which I personally prefer (religious war alert) as it seems more readable to me. You can't confuse a $ with a quote. smile

Dusty

Offline

#3 2007-01-17 11:20:18

iphitus
Forum Fellow
From: Melbourne, Australia
Registered: 2004-10-09
Posts: 4,927

Re: Shell Script Refuses to Cooperate

Dusty wrote:

the scripts are telling you to use backticks, the ones under the ~ sign on your keyboard, not single quotes. You can also use EXTIP=$(eth0addr), which I personally prefer (religious war alert) as it seems more readable to me. You can't confuse a $ with a quote. smile

Dusty

there's something about $() being more proper or something too, as all of rc.sysinit, and mkinitcpio uses $().

James

Offline

#4 2007-01-17 12:31:37

T-Dawg
Forum Fellow
From: Charlotte, NC
Registered: 2005-01-29
Posts: 2,736

Re: Shell Script Refuses to Cooperate

bash wants to depreciate the use of backticks with $() in the future. Not sure exactly when. It probably has something to do with easily confusing backticks with single quotes.

Offline

#5 2007-01-17 14:40:48

Dusty
Schwag Merchant
From: Medicine Hat, Alberta, Canada
Registered: 2004-01-18
Posts: 5,986
Website

Re: Shell Script Refuses to Cooperate

historically, sh used the backticks. Bash introduced the $() syntax because its much easier to nest them. Bash keeps the backticks for backwards compatibility.

The issue of which is more proper is argued across the Internet. One side argues that $() is more modern, easier to read, and nestable. The other side argues that backticks are more portable and operate across legacy systems. If rc.sysinit and mkcpio use $() syntax, it means Arch devs are modern, but we knew that already. ;-)
Dusty

Offline

#6 2007-01-17 16:34:11

phrakture
Arch Overlord
From: behind you
Registered: 2003-10-29
Posts: 7,879
Website

Re: Shell Script Refuses to Cooperate

Clarification:
The Single Unix Specification (SUS) has a shell portion (XSH I think? something like that).  That spec rarely changes, but it is well known that in the next release of the spec, backticks will be deprecated for $() due to numerous issues, such as less complex grammar rules and easier nesting.
Keep in mind that the next spec is years away and this is a DEPRECATION - meaning it will still be valid, just discouraged.  In essence, backticks will be around for something like 15 years still, at the rate standard organizations move.

mkinitcpio uses $() because it makes more sense to me, and looks cleaner, in addition to the above.

Offline

Board footer

Powered by FluxBB