Results 1 to 6 of 6

Thread: executing bash scripts does not work

  1. #1
    Join Date
    Jan 2012
    Beans
    55

    executing bash scripts does not work

    i'm currently new to bash and i have a tr1.sh script in a folder in the Desktop. but when i tried bash tr1.sh , sh tr1.sh , . tr1.sh or ./tr1.sh, and error will show
    "li: command not found" . anyone can help. tnx

  2. #2
    Join Date
    Aug 2008
    Location
    Sweden
    Beans
    302
    Distro
    Ubuntu 14.04 Trusty Tahr

    Re: executing bash scripts does not work

    The script are trying to run a command named li, but you no app/tool installed with that name.

    What's the content of the script?
    This is my signature

  3. #3
    Join Date
    Jan 2012
    Beans
    55

    Re: executing bash scripts does not work

    Quote Originally Posted by DarkAmbient View Post
    The script are trying to run a command named li, but you no app/tool installed with that name.

    What's the content of the script?
    this is the content of the script
    Code:
    for i in `li -A`
    do
        newname=`echo $i | tr A-Z a-z`
        mv $i $newname
    done
    i am trying to replace the names of the files ( FILE1 FILE2 FILE3 FILE4 FILES ) into lowecase as ( file1 file2 file3 file4 files)

  4. #4
    Join Date
    Jul 2007
    Location
    Poland
    Beans
    4,499
    Distro
    Ubuntu 14.04 Trusty Tahr

    Re: executing bash scripts does not work

    you probably wanted ls but you shouldn't use ls for anything in scripts.

    Code:
    for f in *; do [ -f "$f" ] && mv -- "$f" "${f,,}"; done
    should do the trick

    [ -f "$f" ] is a test for being a file, just in case there are dirs you don't want to touch. If not, mv alone will do.
    if your question is answered, mark the thread as [SOLVED]. Thx.
    To post code or command output, use [code] tags.
    Check your bash script here // BashFAQ // BashPitfalls

  5. #5
    Join Date
    Jan 2012
    Beans
    55

    Re: executing bash scripts does not work

    i solved it. i just mistyped ls into li

  6. #6
    Join Date
    Feb 2007
    Location
    Romania
    Beans
    Hidden!

    Re: executing bash scripts does not work

    As Vaphell already mentioned it, you shouldn't use for i in $(ls). See BashPitfalls 01 (link in my signature). Also check out BashPitfalls 02 and 30 and http://mywiki.wooledge.org/CommandSubstitution .

    Vaphell's solution should do the trick, but it can be improved. You only have to rename the files which have at least one uppercase letter:
    Code:
    for f in *[[:upper:]]*; do ...
    For more examples you can check out BashFAQ 030.

Bookmarks

Posting Permissions

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