Find the answer to your Linux question:
Results 1 to 3 of 3
Hello Guys, I am trying to store output of command to an array and then want to print, but it showing an error that "bad substitution". I am not getting ...
  1. #1
    Just Joined!
    Join Date
    Oct 2011
    Posts
    17

    How to store output of command to an array

    Hello Guys,

    I am trying to store output of command to an array and then want to print, but it showing an error that "bad substitution". I am not getting why it's happening.

    Can anyone help me?

    Code:
    #!/usr/bin/sh
    
    hr=0
    min=0
    
    i=1
    
    last $1 | grep -w `date "+%b"` | grep -v '\(0[2-9]:.*\)' | grep -vw sshd | cut -
    c 66- | tr -d "[ ]\(\)" | grep -v '[a-z].*' | while read line
    do
            array[ $i ]="$line"
            i=$i+1
    done
    
    #print an array
    for i in "${array[]}"
    do
        echo $i
    done
    Thanking You,

  2. #2
    Linux Enthusiast scathefire's Avatar
    Join Date
    Jan 2010
    Location
    Western Kentucky
    Posts
    616
    Have you tried using Bash, instead of sh?
    linux user # 503963

  3. #3
    Just Joined!
    Join Date
    Oct 2011
    Posts
    17
    Thanks, problem is resolved.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...