In POSIX shell, we don't have arrays, but we can iterate over a list like this:
But let's say we want "Mr. Slate" in the list.
We know we can't just stick him in there like this:
list="Fred Barney Mr. Slate"
Because word splitting would split Mr. Slate into two words.
So, we could play with IFS
But what if we don't want to fool with the IFS.
We could use eval
Notice we had to put literal quotation marks around Mr. Slate in the list. That's understandable.
Had to use single quotes to mark the beginning and end of eval block.
And had to make sure $list is NOT in single quotes.
This works, but it's kind of clumsy.
Is there a better way? Without messing with IFS and keeping with POSIX sh.
The reason I say this: when I do an eval block, it doesn't get the nice syntax highlighting in my editor! (gvim) It seems whenever I do an eval block, I never get it right the first time. Or second time!
Sometimes I do the eval thing within a function, as a way of "passing by reference" (I think that's what it's called). I know Bash has references. I'm trying to get in the habit of "portable" scripting. Or at least, make it run in Dash.
I have a file input.txt which have loads of weird characters, html tags and useful materials. I want to display 35 characters after the word "description" excluding weird characters like $&lmp and without html tags in the new file output.txt. Help me. Thanx in advance. I have attached the input... (4 Replies)
Hello,
I have a script that "validates" a ZIP file that look like this
AAA_20120801.zip =>
x~back end~20120801.TXT
y~time in~20120801.TXT
z~heat_chamber~20120801.TXT
AAA_20120801.ctlMy task is to compare its contents (i.e the list of files contained inside) with the control file that is... (2 Replies)
Hi all,
some small script with eval turned me to crazy.
my OS is linux
Linux s10-1310 2.6.16.53-0.8.PTF.434477.3.TDC.0-smp #1 SMP Fri Aug 31 06:07:27 PDT 2007 x86_64 x86_64 x86_64 GNU/Linux
below script works well
#!/bin/bash
eval ssh remotehost date
eval ssh remotehost ls
below... (1 Reply)
According to the POSIX specifications eval is a special shell built-in, which should imply that variable assignments specified together with it should remain in effect after the built-in completes. Thus one would expect IFS to be changed after this:
var=$'a\nb c'
$ IFS=$'\n' eval '
for i in... (4 Replies)
I am stuck on something that should really be simple, and was looking for some help..
I am new to shell scripting.Need help on this.....
The script is to find the stale nfs.
cat file
- - - - /abcd/1234
I am writing the script to check the nfs errors of above file
... (3 Replies)
Hi, experts.
Whould anybody clear explay me difference and usage of these 3 commands (particulary in bash) :
exec
eval
source
I've tryed to read the manual pages but did not get much.
Also could not get something useful from Google search - just so much and so not exactly, that is... (3 Replies)
Greetings.
I am struggling with a shell script to make my life simpler, with a number of practical ways in which it could be used. I want to take a standard text file, and pull the 'n'th word from each line such as the first word from a text file.
I'm struggling to see how each line can be... (5 Replies)