0

I have set a variable with some value, when i am displaying it value with echo command it displays the value correctly but when i use this variable inside command it does not work . can anyone please help in this.

echo $hiteshobject
ameras0009.abc.com:/D 'ameras0009.abc.com [/D]'

26:/home/a-hkat # omnidb -winfs "${hiteshobject}"
No objects were found.

26:/home/a-hkat # echo "${hiteshobject}"
ameras0009.abc.com:/D 'ameras0009.abc.com [/D]'

26:/home/a-hkat # omnidb -winfs ameras0009.abc.com:/D 'ameras0009.abc.com [/D]'

SessionID        Started  Duration Object Status                   Size [KB]      NumberOfErr
=============================================================================================
2017/02/20-379       03:00:28 08:14:24 Running                           3769280          0
2017/02/20-221       03:00:28 00:13:25 Completed                         3769280          0
2017/02/19-122       03:00:31 30:07:24 Failed                                  0          0

This article describe to use array . Actually i am new to bash scripting so can please help me how i can use array in my case.

Thanks in advance.

  • See [BashFAQ #50](http://mywiki.wooledge.org/BashFAQ/050). And don't trust `echo` -- see [BashPitfalls #14](http://mywiki.wooledge.org/BashPitfalls#echo_.24foo), but *also* understand that `echo "$foo"` gives you the value of the *data* in $foo, whereas quotes -- to control parsing and word-splitting -- need to be *syntax*, not *data*. – Charles Duffy Feb 20 '17 at 16:05
  • i tried it many ways but this is not working for me. Can u give you more input as i am new to bash scripting. thanks in advance – Hitesh Kataria Feb 20 '17 at 19:31
  • `hitescharray=( ameras0009.abc.com:/D 'ameras0009.abc.com [/D]' ); omnidb -winfs "${hitescharray[@]}"` – Charles Duffy Feb 20 '17 at 20:20
  • The above creates a *two-element* array, where the first element is `ameras0009.abc.com:/D`, and the second element is `ameras0009.abc.com [/D]`. You'll note that neither element contains any literal quotes -- the quotes are in both commands *syntactic*, telling the shell how to interpret other characters. – Charles Duffy Feb 20 '17 at 20:20
  • ...that said -- everything I gave above was also explained in BashFAQ #50. I'd suggest reading that FAQ entry again if any part of suggested command isn't clear. – Charles Duffy Feb 20 '17 at 20:21
  • Hi Charles thanks for ur support it works for me , i have to use above syntax with eval command as mention in BashFAQ #50 and it work for me. – Hitesh Kataria Mar 01 '17 at 16:10
  • BashFAQ #50 gives you advice on how to avoid `eval` -- which is prone to bugs, including security-related ones; [BashFAQ #48](http://mywiki.wooledge.org/BashFAQ/048) for more. I would suggest leveraging that advice. – Charles Duffy Mar 01 '17 at 16:15

0 Answers0