0
#!/bin/bash
arr=('Debasish')
arg=""
length=${#arr[i]}
echo $length
#thing=($(i=0; while [ $i -lt ${#foo} ] ; do echo ${foo:$i:1} ; i=$((i+1)) ; done))

for (( i=0; i<$length; i++ ))
do
    echo ${arr:$i:1}
    a1="${arr:$i:1}"
    A1=$(printf '%d\n' "'$a1")
    echo $A1
    arg="$arg $A1"

done

echo ""
echo $arg
echo ""

brr=($arg)
brg=""
brr_length=${#brr[@]}
for (( i=0; i<brr_length; i++ ))
do
    echo ${brr[$i]}
    declare -i j=${brr[$i]}
    k=$(printf \\$(printf '%03o' $j))
    echo $k
    brg="$brg$k"
done`enter code here`
echo $brg

In the above code i have used an array to input a string and convert it into ASCII decimal values and its reverse.I want to know in place of a string how can i take a file as an input to the array and the process gets executed for the whole of the file.

  • ...so the question is "how can I populate an array from a file"? There's rather a lot of unnecessary content for that -- we generally ask that questions be *minimal*, cut down to the shortest code necessary to illustrate the question; see http://stackoverflow.com/help/mcve – Charles Duffy Apr 02 '17 at 16:02
  • (BTW, you might try running through http://shellcheck.net/ -- there's quite a number of quoting bugs here). – Charles Duffy Apr 02 '17 at 16:03

0 Answers0