mukesh.lalwani,
With any Korn shell, you can use arrays with a numeric subscript for subscripts from 0 to about 2047. With ksh93 and with bash you can use numeric subscripts with larger values or with string valued subscripts. The syntax is:
or for multiple array elements:
Or, with any shell based on Bourne shell syntax, you can use eval as shown in the link you referenced. Note that eval can be a security risk if any of the code that you are feeding to eval is supplied by a user. But, eval is generally safe if all of the strings being evaluated by eval are hardcoded into your script.
RTY,
prints whatever $dbname expands to followed by whatever $i expands to not to the contents of the variable named by dbname followed by the expansion of $i.
.
.
.
Please help me understand why substitution is not working here. and what could be done to get the output as tree
.
.
.
Well, substitution IS working here, but it may not yield what you expected. $(db_name$i) is an instance of
Quote:
Command Substitution
Command substitution allows the output of a command to replace the command name. There are two forms:
$(command)
or
`command`
Bash performs the expansion by executing command and replacing the command substitution with the standard output of the command, with any trailing newlines deleted.
$((db_name$i)) performs
Quote:
Arithmetic Expansion
Arithmetic expansion allows the evaluation of an arithmetic expression and the substitution of the result. The format for arithmetic expansion is:
$((expression))
The old format $[expression] is deprecated and will be removed in upcoming versions of bash.
The expression is treated as if it were within double quotes, but a double quote inside the parentheses is not treated specially. All tokens in the expression undergo
parameter and variable expansion, command substitution, and quote removal. The result is treated as the arithmetic expression to be evaluated. Arithmetic expansions
may be nested.
The evaluation is performed according to the rules listed below under ARITHMETIC EVALUATION. If expression is invalid, bash prints a message indicating failure and no
substitution occurs.
$(`(db_name$i)`) is, mmmm, say, a duplicate command substitution. Results, if any, may be dubious.
---------- Post updated at 10:38 ---------- Previous update was at 10:34 ----------
And, the db_nameis not evaluated as the $ sign is missing.
And, what do you expect "the output as tree" to look like?
Hi
what i want:
listing files in a special range
ls -lrt 20120601{05..06}*
...
-rw-rw-r-- 1 imp imp 279 1. Jun 07:51 201206010550
-rw-rw-r-- 1 imp imp 279 1. Jun 07:01 201206010600
-rw-rw-r-- 1 imp imp 279 1. Jun 07:11 201206010610
-rw-rw-r-- 1 imp imp 279 1. Jun 07:21... (1 Reply)
I'm trying to do an ls from inside of a ksh script. I loop through the results one line at a time and attempt to do a substitution using sed to convert YYYYMMDD from the older files into the newer files. Basically sometimes the ETL load runs over midnight and half the files are off by one day... (3 Replies)
Hello,
In bash I can use the following:
TMP=12345
MID=${TMP:1:1}
the expected result is: 2
but when using KSH I'm getting a ''bad substitution" error.
What is the correct syntaxin ksh?
Thanks (2 Replies)
Give the code:
set line = 2
set year = `sed -n '2p' file
while ($line < 500)
echo $line > f.txt
@ line = $line + 1
end
How do I utilize the variable $line in the code instead of the number 2. I'm using this in a while loop and counter. I've tried quoting it, double/single... (1 Reply)
Hi
I have a variable BIT1 which holds some value. Is there a way to retrieve the value of this variable indirectly via another variable, lets say SUBSET_BIT_NUM=1, so the call will look something like this:
sundev1 $ echo ${BIT${SUBSET_BIT_NUM}}
ksh: ${BIT${SUBSET_BIT_NUM}}: bad substitution
... (3 Replies)
Hello,
i have another sed question.. I'm trying to do variable substition with sed and i'm running into a problem.
my var1 is a string constructed like this:
filename1 filerev1 filepath1
my var2 is another string constructed like this:
filename2 filerev2 filepath2
when i do... (2 Replies)
Hi,
Following code is working in bash but not in ksh.
Can someone please send me an alternative?
#!/bin/ksh
fname="EOA.dmp"
echo $fname
logname=${fname/.dmp/.log}
echo $logname
I am getting below error in ksh
"testcmd: logname=${fname/.dmp/.log}: 0403-011 The specified substitution... (3 Replies)
Following code is working in bash but not in ksh.
Can someone please send me an alternative?
#!/bin/ksh
fname="EOA.dmp"
echo $fname
logname=${fname/.dmp/.log}
echo $logname
I am getting below error in ksh
"testcmd: logname=${fname/.dmp/.log}: 0403-011 The specified substitution is not... (2 Replies)
Hi folks
Please let me know if anyone knows how to handle this.
My KSH script -> testscript.ksh
cmd=$1
ENV="devl"
echo $cmd
This is how I call the script
./testscript.ksh 'ps -ef | grep br$ENV'
How do I get this to print the below text i.e $ENV should be substituted with the value... (5 Replies)
Hello,
I thought it was possible to use several time a #! entry on a script but it doesn't seems to work. My need is to have a part of a ksh script without substitution so it would look like
#!/bin/ksh
--
first part
---
#!/bin/ksh -f
--
part without substitution
--
#!/bin/ksh
--... (2 Replies)