LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 11-10-2016, 04:06 AM   #16
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,912

Rep: Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513

The entire thing gets simpler with Perl... as you are under control of how variables get used at each step.

At one time I used a perl script to interpret a network configuration file... and made the configuration file executable, using a "#!/etc/network.p" in the configuration file to invoke the Perl script.

Much easier than trying to get bash to do it - and it shortened the configuration file.
 
Old 11-10-2016, 04:13 AM   #17
break_da_funk
LQ Newbie
 
Registered: Apr 2016
Posts: 15

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by jpollard View Post
The entire thing gets simpler with Perl... as you are under control of how variables get used at each step.

At one time I used a perl script to interpret a network configuration file... and made the configuration file executable, using a "#!/etc/network.p" in the configuration file to invoke the Perl script.

Much easier than trying to get bash to do it - and it shortened the configuration file.
In my case configuration file analysis is done by some awk script which outputs options for pppd. Then pppd is executed with fixed options + options read by awk script. I tried to combine fixed options and from configuration file with awk but I realized that this is user arguments analysis - I don't want to do that.
Anyway thank You for the answer
 
Old 11-10-2016, 06:44 AM   #18
break_da_funk
LQ Newbie
 
Registered: Apr 2016
Posts: 15

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by jpollard View Post
This is not obvious... and may not be the best way...

If you replace the following line in the test.sh script
Code:
./arguments_count.sh $my_args
with

Code:
eval ./arguments_count.sh $my_args
You get the same answer as the direct string returns. This happens because you are forcing an additional evaluation of the strings... and that converts the '4 and 5' parameters into the string '4 5'.

This approach may not even work in all cases - as the space character between the 4 and 5 will have been evaluated, so if you expected to pass a tab character it won't be there as previous evaluations removed it.

This will not help if have multiple nested structures...

Easier to use perl or python..
Eval also solve the problem.
 
Old 11-10-2016, 11:33 AM   #19
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,850

Rep: Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309
do not use eval
http://stackoverflow.com/questions/1...-i-use-instead
 
Old 11-10-2016, 12:17 PM   #20
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,912

Rep: Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513
Quote:
Originally Posted by pan64 View Post
Is also another way of saying "don't be portable". If you are using the Bourne shell you can't use most of those recommendations as the facilities don't exist.

Most UNIX like systems do have bash available... but not necessarily provided by the distribution.
 
  


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
How to pass string variable as command parameter in shell script? prasad1990 Linux - Newbie 6 03-23-2015 12:48 AM
[SOLVED] Bash Shell Script - Store a variable as a string not an integer RML1992 Linux - General 8 09-12-2012 09:19 AM
how to read shell variable in /etc/auto.direct map for autofs service UltraSoul Linux - General 8 06-05-2009 07:21 AM
Need shell script to concatenate a string and a variable into a directory name AwesomeMachine Linux - Newbie 2 05-07-2006 03:42 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

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