xerox
February 27, 2011, 11:58pm
1
this is my code
declare -a USERCERT
declare -a CACERT
declare -a KEYSRC
this is the error
+ declare -a USERCERT
./clone.sh: 1: declare: not found
+ declare -a CACERT
./clone.sh: 1: declare: not found
+ declare -a KEYSRC
./clone.sh: 1: declare: not found
Suggest resolution....
kshji
February 28, 2011, 12:04am
2
# ksh
typeset -A array
# bash
declare -a array
declare
is a bashism not found in other shells. In ksh, use typeset
.
And most shells do not have arrays at all.
xerox
February 28, 2011, 12:52am
4
i need it in shell script....
Is it not possible to define my own array name?
kshji
February 28, 2011, 1:03am
5
What is your shell ? ksh, bash, ...
And most of use case, you don't need to define array. Use it.
a[1]=value
a=( * )
set -A array -- $*
1 Like
xerox
February 28, 2011, 1:10am
6
bash...
so the array size doesnt't matter?
set -A array -- $*
what does this line do?
Yes ... if you are using a shell which supports arrays.
First, don't declare
the arrays; just assign values to them.
---------- Post updated at 01:21 AM ---------- Previous update was at 01:13 AM ----------
xerox:
bash...
If you were running the script in bash, you wouldn't have seen those error messages.
No (so long as there is enough memory).
set -A array -- $*
what does this line do?
In bash, there is no -A option to set.
In ksh, it assigns all the words (not the arguments) on the command line as elements in the array named array
.
The bash equivalent (which also works in ksh93) is:
array=( $* )
Though what was probably meant was:
set -A array -- "$@"
Which should be written:
array=( "$@" )
1 Like
xerox
February 28, 2011, 6:08am
8
Ok..ill try once more....thanks...
---------- Post updated at 04:38 PM ---------- Previous update was at 12:09 PM ----------
this is my code :
cert=`cat $usr_cert`
for i in $cert ; do
USERCERT[$COUNT]=$i
((COUNT++))
done
this is the error I'm getting:
File name too long
+ COUNT++
./clone.sh: 1: COUNT++: not found
./clone.sh: 1: Bad substitution
please explain the error and suggest a resolution....
COUNT=0
while read i; do
USERCERT[$COUNT]="$i"
COUNT=$(( $COUNT + 1 ))
done < $usr_cert
while IFS= read -r i
do
USERCERT+=( "$i" )
done < "$usr_cert"
Or:
IFS=$'\n'
USERCERT=( $( < "$usr_cert" ) )
Or (bash 4):
mapfile -t USERCERT < "$usr_cert"
xerox
February 28, 2011, 7:53am
11
what does this error indicate:
./clone.sh: 1: Bad substitution
Probably that you used an invalid variable name in a parameter expansion.