You are not logged in.
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
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. ![]()
Dusty
Offline
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.
Dusty
there's something about $() being more proper or something too, as all of rc.sysinit, and mkinitcpio uses $().
James
Offline
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
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
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