Find the answer to your Linux question:
Page 3 of 3 FirstFirst 1 2 3
Results 21 to 24 of 24
Like Tree15Likes
Why does that command *not* work when you put it in a shell script but works fine from the command line?...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #21
    Linux User
    Join Date
    Dec 2011
    Location
    Turtle Island West
    Posts
    370

    Why does that command *not* work when you put it in a shell script but works fine from the command line?

  2. #22
    Linux Engineer
    Join Date
    Apr 2012
    Location
    Virginia, USA
    Posts
    896
    Because the sub shell has no 'history' file.

  3. #23
    Linux User
    Join Date
    Dec 2011
    Location
    Turtle Island West
    Posts
    370
    Quote Originally Posted by mizzle View Post
    Because the sub shell has no 'history' file.
    Ah yes. Of course.

    history-top-ten.sh :
    Code:
    #!/bin/sh
    
    # read the history file,
    cat $HOME/.bash_history | \
    # count the items into array CMD[]
    awk '{ CMD[$1]++; count++; } END        \
        {                                   \
            for (a in CMD)                  \
                print CMD[a] " "            \
                (CMD[a]/count)*100 "% " a;  \
        }'                  | \
    # remove any non-system items
    grep -v "./"            | \
    # fill 3 space delimited columns to prettify
    column -c3 -s " " -t    | \
    # sort by numerical value and then reverse it
    sort -nr                | \
    # add line numbering
    nl                      | \
    # and print the first 10
    head -n10
    Lovely.
    Dapper Dan and Lakshmipathi like this.

  4. #24
    Linux Guru Lakshmipathi's Avatar
    Join Date
    Sep 2006
    Location
    3rd rock from sun - Often seen near moon
    Posts
    1,758
    Slightly related one - common mistakes by commandline users ! I have done 'echo $shell' once or twice

    Webminal Online Linux Terminal
    First they ignore you,Then they laugh at you,Then they fight with you,Then you win. - M.K.Gandhi
    -----
    FOSS India Award winning ext3fs Undelete tool www.giis.co.in. Online Linux Terminal http://www.webminal.org

Page 3 of 3 FirstFirst 1 2 3

Posting Permissions

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