RetroPie forum home
    • Recent
    • Tags
    • Popular
    • Home
    • Docs
    • Register
    • Login

    shell scripting topic

    Scheduled Pinned Locked Moved Ideas and Development
    shellshell scriptprogramming
    191 Posts 10 Posters 89.1k Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • meleuM
      meleu @Sano
      last edited by

      @sano whoops! Didn't catch those little words 😅

      Thanks Sano-san. And yeah, I learned more tricks!

      • Useful topics
      • joystick-selection tool
      • rpie-art tool
      • achievements I made
      SanoS 1 Reply Last reply Reply Quote 1
      • SanoS
        Sano @meleu
        last edited by

        @meleu Just FYI, you could just have used date +%-H ;)
        Glad to see you here again BTW !

        meleuM 1 Reply Last reply Reply Quote 1
        • meleuM
          meleu @Sano
          last edited by

          @sano ouch! Looks like I need RTFM some more...

          From the date man page:

                 By default, date  pads  numeric  fields  with  zeroes.   The  following
                 optional flags may follow '%':
          
                 -      (hyphen) do not pad the field
          

          Thanks again, Sanso-sensei!

          • Useful topics
          • joystick-selection tool
          • rpie-art tool
          • achievements I made
          SanoS 1 Reply Last reply Reply Quote 1
          • SanoS
            Sano @meleu
            last edited by

            @meleu I really deserve no special credit for this, I just remembered something like this existed, probably had to use it in the past, too :)

            1 Reply Last reply Reply Quote 0
            • cyperghostC
              cyperghost
              last edited by cyperghost

              A common mistake is often made by using grep.
              It is often told that grep finds a total of all search strings within a text file due the -c switch. That is total nonsense .... -c just counts lines

              So we miss

              hello hello hello hello
              hello
              
              grep -c hello
              2
              

              We use a small hack ;)
              Better is to use the -o option is will show occourences of search string listed in newline and now we pipe to wc -l ... and count lines again - now we catched them all ;)

              hello hello hello hello
              hello
              
              grep -o hello | wc -l
              5
              
              1 Reply Last reply Reply Quote 0
              • cyperghostC
                cyperghost
                last edited by cyperghost

                @meleu

                EDIT BEGIN
                I think I found a good solution with pure bash
                But maybe some knows a better one ;)

                val=${#Unix[@]}
                for ((i=0; i<$val; i+=1)); do
                

                EDIT END


                Is there something that can be made easier (more efficient) than this script?
                I want to merge two arrys
                A1=(1 2 3)
                A2=(one two there)
                the result should be A3
                A3=(1 one 2 two 3 three)

                It works with this script.
                But first... I want to avoid any counters (if possible)
                Do you know a nice trick to count up values {0..6} works only with fixed characters not as variable. So {0..6} is fine {0..$arraysize} not

                #!/bin/bash
                # A small script to show how to merge two arrays
                # with alternating values (exp. for creating arrays for dialogs)
                
                # Example Array
                Unix=("Debian" "Red hat" "Ubuntu" "Suse" "Fedora" "UTS" "OpenLinux")
                Shell=("bash" "csh" "jsh" "rsh" "ksh" "rc" "tcsh")
                
                # Check if both arrays got some size
                [[ ${#Unix[@]} -eq ${#Shell[@]} ]] || exit 1
                echo "Both arrays got same size -- Proceed"
                
                val=$((${#Unix[@]}-1))
                echo $val
                for i in $(seq 0 $val); do
                    echo "Merging ${Unix[$i]} and ${Shell[$i]}"
                    UnixShell+=("${Unix[$i]}" "${Shell[$i]}")
                done
                
                echo "${UnixShell[@]}"
                
                meleuM 1 Reply Last reply Reply Quote 0
                • meleuM
                  meleu @cyperghost
                  last edited by

                  @cyperghost both methods are perfectly valid (using a for to iterate through all items).

                  • Useful topics
                  • joystick-selection tool
                  • rpie-art tool
                  • achievements I made
                  cyperghostC 1 Reply Last reply Reply Quote 0
                  • cyperghostC
                    cyperghost @meleu
                    last edited by

                    @meleu thanks for the feedback -- I appreciate it ;)
                    Come on ... take a look in the MAME RoW now - if you have time ;)

                    1 Reply Last reply Reply Quote 0
                    • hiulitH
                      hiulit
                      last edited by

                      FYI, I'll release a new version of RetroPie Shell Script Boilerplate soon-ish.

                      This is a template for building shell scripts for RetroPie, with some helper functions, dialogs, etc.

                      My little contributions to the RetroPie project:

                      • Shell-Script-Boilerplate
                      • Fun-Facts-Splashscreens
                      • Limit-Last-Played-Games
                      1 Reply Last reply Reply Quote 3
                      • hiulitH
                        hiulit
                        last edited by

                        Well, here it is! A new version of RetroPie Shell Script Boilerplate.

                        This is a template for building shell scripts for RetroPie.

                        I've added examples of the following dialog boxes:

                        • --infobox
                        • --yesno
                        • --msgbox
                        • --menu

                        All the dialogs can be found at utils/dialogs.sh

                        I've also moved some functions to utils/base.sh.

                        My little contributions to the RetroPie project:

                        • Shell-Script-Boilerplate
                        • Fun-Facts-Splashscreens
                        • Limit-Last-Played-Games
                        1 Reply Last reply Reply Quote 1
                        • First post
                          Last post

                        Contributions to the project are always appreciated, so if you would like to support us with a donation you can do so here.

                        Hosting provided by Mythic-Beasts. See the Hosting Information page for more information.