Find the answer to your Linux question:
Results 1 to 5 of 5
hi I want programming a similar system like init-V with the rc2.d/*S scripts like this: in a folder "$HOME/.modules" are some scripts like this: 10_get_random.sh 12_autoresize.sh 20_add_weather.sh 30_set_wallpaper.sh ok, how ...
  1. #1
    Just Joined!
    Join Date
    Aug 2007
    Posts
    28

    bash script filename expansion inside variable

    hi

    I want programming a similar system like init-V with the rc2.d/*S scripts like this:

    in a folder "$HOME/.modules" are some scripts like this:
    10_get_random.sh
    12_autoresize.sh
    20_add_weather.sh
    30_set_wallpaper.sh

    ok, how can I start all this scripts in alphabethical order from a other script?

    It should test if 10* exist and if yes, execute it, then, inc by one and try 11* to execute it if it exist, and so on... to 99*...

    so, I have a flexible system to insert later other modules without changing the main-script (like the Init-V System with the rc?.d)

    my example now is this, but the Filename-Expansion don't work right:

    Code:
         13     i=10
         14     while [[ "$i" -lt 99 ]]; do
         15         EXE_FILE=$HOME/.desk-art/modules/$i*
         16 
         17         # test if filename exist:
         18         if [ -r "$EXE_FILE" ]; then
         19             # exec script:
         20             bash $EXE_FILE
         21         fi  
         22         
         23         # calculate next
         24         i=$[$i+1]
         25     done
    any tips for me? (bash-version is 3.2.5)
    thank you for your ideas

  2. #2
    Linux Enthusiast meton_magis's Avatar
    Join Date
    Oct 2006
    Location
    arizona
    Posts
    665
    you may want to look into something like this.

    cd $HOME/.desk-art/modules/
    ls -1 [0-9][0-9]_*.sh | sort -n | awk '{print "./" $1}' | sh

    This will execute 1 script at a time (I'm pretty sure anyway) and execute them sequentialy.

    it is a lot less code, and is much more efficient since you're not testing 10-99 for if files exist.
    New to the internet, technical forums, or the hacker / open source community??
    Read this to learn good posting habits http://www.catb.org/~esr/faqs/smart-questions.html

    RHCE for RHEL version 5
    RHCT for RHEL version 4

  3. #3
    Just Joined!
    Join Date
    Aug 2007
    Posts
    28

    [solved]

    big thanks! Your idea is more usefull than mine. Now, it works fine.

  4. #4
    Linux Enthusiast meton_magis's Avatar
    Join Date
    Oct 2006
    Location
    arizona
    Posts
    665
    cool, glad I could help.
    New to the internet, technical forums, or the hacker / open source community??
    Read this to learn good posting habits http://www.catb.org/~esr/faqs/smart-questions.html

    RHCE for RHEL version 5
    RHCT for RHEL version 4

  5. #5
    Linux User
    Join Date
    May 2008
    Location
    NYC, moved from KS & MO
    Posts
    251
    You problem can also be solved easily with a single for loop:
    Code:
    for f in $HOME/.desk-art/modules/*.sh; do sh $f; done

Posting Permissions

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