Announcement

Collapse
No announcement yet.

Using elif or else if?

Collapse
This topic is closed.
X
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    #31
    Originally posted by Xplorer4x4 View Post
    Not stupid but already answered. Namely a progress meter and built in notification handling.
    Sorry I missed that. I was thinking you were trying to do something behind the scenes for a cron job.
    FKA: tanderson

    Comment


      #32
      Originally posted by Xplorer4x4 View Post
      Code:
      #Exec=searchforarchives.sh %U
      This line is commented out try deleting the #

      As for the success dialog I am not sure it will work with this script as is, find returns true if any files where found or not so will always give you the success popup. The only way I can think of solving this is to store the output from find in a variable and passing this variable to ark later on after you check its contents.

      Bash Script:
      Code:
      #!/bin/bash
      searchextractrar() {
          input="${1}"
      
          files=$(find -iregex '.*[^p][^a][^r][^t]..\.rar\|.*part0[^023456789]\.rar\|.*/.?.?.?.?.?.?\.rar')
          if [[ -z "${files}" ]]; then
              ark --batch --autodestination ${files};
          else
              kdialog --passivepopup "No archives found in ${input}." 60
              return 1  #Change to exit 1 to stop the script on first failure
          fi
      }
      
      ...
      As for the space issue this might be of interest:

      Code:
      % cat test#!/bin/bash
      echo $@
      echo "Testing \$@"
      for a in $@; do
         echo $a
      done
      echo "Testing \$*"
      for a in $*; do
         echo $a
      done
      echo "Testing \"\$@\""
      for a in "$@"; do
         echo $a
      done
      echo "Testing \"\$*\""
      for a in "$*"; do
         echo $a
      done
      echo "Testing for a"
      for a; do
         echo $a
      done
      echo "Testing shift"
      while [[ -n "$1" ]]; do
          echo $1
          shift
      done
      This script shows the common ways to iterator over all the arguments below is some example output when run with the 5 arguments: 1 2 "4 5" " " 6\ 7
      Note that "4 5" is a single argument as is " " and 6\ 7 but 1 and 2 are separate arguments. This is so you can see how bash treats each of the arguments.
      Code:
      % bash test 1 2 "4 5" " " 6\ 7
      1 2 4 5 6 7
      Testing $@
      1
      2
      4
      5
      6
      7
      Testing $*
      1
      2
      4
      5
      6
      7
      Testing "$@"
      1
      2
      4 5
      
      
      6 7
      Testing "$*"
      1 2 4 5 6 7
      Testing for a
      1
      2
      4 5
      
      
      6 7
      Testing shift
      1
      2
      4 5
      
      
      6 7
      This shows the importance of using the write variable as well as proper quoting in bash.

      You should be able to use any of the variants that produce the right output (I would go for "for a; do...").

      Lastly this part of the ark man page might be of interest:
      -o, --destination directory
      Default the extraction directory to directory. If not passed, the current path is used.
      ...
      -e, --autodestination
      The destination argument will be set to the path of the first file supplied.
      Default the extraction directory to directory. If not passed, the current path is used.
      Last edited by james147; Nov 10, 2012, 07:05 PM.

      Comment


        #33
        Originally posted by james147 View Post
        This line is commented out try deleting the #

        As for the success dialog I am not sure it will work with this script as is, find returns true if any files where found or not so will always give you the success popup. The only way I can think of solving this is to store the output from find in a variable and passing this variable to ark later on after you check its contents.

        Bash Script:
        Code:
        #!/bin/bash
        searchextractrar() {
            input="${1}"
        
            files=${find -iregex '.*[^p][^a][^r][^t]..\.rar\|.*part0[^023456789]\.rar\|.*/.?.?.?.?.?.?\.rar'}
            if [[ -z "${files}" ]]; then
                ark --batch --autodestination ${files};
            else
                kdialog --passivepopup "No archives found in ${input}." 60    return 1  #Change to exit 1 to stop the script on first failure
            fi
        }
        
        ...
        Everything after this lost me lol.

        First the comment, that was likely a typo. I have 2 exec lines so I can go back and forth from konsole output to background processing quickly.

        Secondly, the new script.
        Code:
        /usr/local/bin/searchforarchives.sh: line 6: ${find -iregex '.*[^p][^a][^r][^t]..\.rar\|.*part0[^023456789]\.rar\|.*/.?.?.?.?.?.?\.rar'}: bad substitution
        I assume this is because kate wants to add an underscore instead of a space after find. Looking in to this strange occurrence now.
        OS: Kubuntu 12.10/Windows 8
        CPU: Intel Core i7 2600K
        Motherboard: Gigabyte GA-Z77X-UD5H
        Memory: 2x4GB Corsair Dominator
        Graphics Card: MSI R7770
        Monitor: Dell 2208WFP
        Mouse: Mionix NAOS 5000
        PSU: Corsair 520HX
        Case: Thermaltake Mozart TX
        Cooling: Thermalright TRUE Black Ultra-120 eXtreme CPU Heatsink Rev C
        Hard Drives: 1x180 GB Intel 330 SSD - 1xWD 1 TB Caviar Black - 1xWD 2 TB Caviar Green - 2xWD 3 TB Caviar Green

        Comment


          #34
          Originally posted by Xplorer4x4 View Post
          Code:
          /usr/local/bin/searchforarchives.sh: line 6: ${find -iregex '.*[^p][^a][^r][^t]..\.rar\|.*part0[^023456789]\.rar\|.*/.?.?.?.?.?.?\.rar'}: bad substitution
          Opps, my bad, it should be $(find ... ) not ${find ...}

          The rest of the post is my saying, and explaing why you should use
          Code:
          for file; do
              searchextractrar ${file}
          done
          or
          Code:
          for file in "${@}" ; do
              searchextractrar ${file}
          done
          instead of
          Code:
          for file in ${@} ; do
              searchextractrar ${file}
          done
          Last edited by james147; Nov 10, 2012, 06:48 PM.

          Comment


            #35
            Originally posted by james147 View Post
            Opps, my bad, it should be $(find ... ) not ${find ...}
            Got a new error now:
            FAILURE (KCmdLineArgs): Argument out of bounds
            Application requests for arg(0) without checking count() first.


            The rest of the post is my saying, and explaing why you should use
            Code:
            for file; do
                searchextractrar ${file}
            done
            or
            Code:
            for file in "${@}" ; do
                searchextractrar ${file}
            done
            instead of
            Code:
            for file in ${@} ; do
                searchextractrar ${file}
            done
            Thanks, I get it now!
            OS: Kubuntu 12.10/Windows 8
            CPU: Intel Core i7 2600K
            Motherboard: Gigabyte GA-Z77X-UD5H
            Memory: 2x4GB Corsair Dominator
            Graphics Card: MSI R7770
            Monitor: Dell 2208WFP
            Mouse: Mionix NAOS 5000
            PSU: Corsair 520HX
            Case: Thermaltake Mozart TX
            Cooling: Thermalright TRUE Black Ultra-120 eXtreme CPU Heatsink Rev C
            Hard Drives: 1x180 GB Intel 330 SSD - 1xWD 1 TB Caviar Black - 1xWD 2 TB Caviar Green - 2xWD 3 TB Caviar Green

            Comment


              #36
              Code:
              kdialog --passivepopup "No archives found in ${input}." 60    return 1  #Change to exit 1 to stop the script on first failure
              Should be
              Code:
              kdialog --passivepopup "No archives found in ${input}." 60
              return 1  #Change to exit 1 to stop the script on first failure

              Comment


                #37
                I actually tried that already. Didnt know if it woudl matter or not but when I tried ti, same error as my last post.
                OS: Kubuntu 12.10/Windows 8
                CPU: Intel Core i7 2600K
                Motherboard: Gigabyte GA-Z77X-UD5H
                Memory: 2x4GB Corsair Dominator
                Graphics Card: MSI R7770
                Monitor: Dell 2208WFP
                Mouse: Mionix NAOS 5000
                PSU: Corsair 520HX
                Case: Thermaltake Mozart TX
                Cooling: Thermalright TRUE Black Ultra-120 eXtreme CPU Heatsink Rev C
                Hard Drives: 1x180 GB Intel 330 SSD - 1xWD 1 TB Caviar Black - 1xWD 2 TB Caviar Green - 2xWD 3 TB Caviar Green

                Comment


                  #38
                  Can you post the complete script and error message? (does it give a line number at all?)

                  Comment


                    #39
                    Code:
                    #!/bin/bash
                    searchextractrar() {
                        input="${1}"
                    
                        files=$(find -iregex '.*[^p][^a][^r][^t]..\.rar\|.*part0[^023456789]\.rar\|.*/.?.?.?.?.?.?\.rar')
                        if [[ -z "${files}" ]]; then
                            ark --batch --autodestination ${files};
                        else
                            kdialog --passivepopup "No archives found in ${input}." 60
                            return 1  #Change to exit 1 to stop the script on first failure
                        fi
                    }
                    
                    for file in "${@}" ; do
                        searchextractrar ${file}
                    done
                    As for the error, that is the complete error. No line number or anything.
                    OS: Kubuntu 12.10/Windows 8
                    CPU: Intel Core i7 2600K
                    Motherboard: Gigabyte GA-Z77X-UD5H
                    Memory: 2x4GB Corsair Dominator
                    Graphics Card: MSI R7770
                    Monitor: Dell 2208WFP
                    Mouse: Mionix NAOS 5000
                    PSU: Corsair 520HX
                    Case: Thermaltake Mozart TX
                    Cooling: Thermalright TRUE Black Ultra-120 eXtreme CPU Heatsink Rev C
                    Hard Drives: 1x180 GB Intel 330 SSD - 1xWD 1 TB Caviar Black - 1xWD 2 TB Caviar Green - 2xWD 3 TB Caviar Green

                    Comment


                      #40
                      Try commenting out the ark line (and add a "echo" after it) see if you get the same error, if you do then try it for the kdialog line. ie
                      Code:
                      #ark --batch --autodestination ${files};
                      echo # Just to stop the syntax error caused by an empty if

                      Comment


                        #41
                        That's what I was thinking(but my brains on stupid mode today lol), so I couldn't think how to do it. No error output that time, so does this mean ark can't be passed a variable in this form?
                        OS: Kubuntu 12.10/Windows 8
                        CPU: Intel Core i7 2600K
                        Motherboard: Gigabyte GA-Z77X-UD5H
                        Memory: 2x4GB Corsair Dominator
                        Graphics Card: MSI R7770
                        Monitor: Dell 2208WFP
                        Mouse: Mionix NAOS 5000
                        PSU: Corsair 520HX
                        Case: Thermaltake Mozart TX
                        Cooling: Thermalright TRUE Black Ultra-120 eXtreme CPU Heatsink Rev C
                        Hard Drives: 1x180 GB Intel 330 SSD - 1xWD 1 TB Caviar Black - 1xWD 2 TB Caviar Green - 2xWD 3 TB Caviar Green

                        Comment


                          #42
                          Been awhile since I got any help on this. Any one willing to lend a hand?
                          OS: Kubuntu 12.10/Windows 8
                          CPU: Intel Core i7 2600K
                          Motherboard: Gigabyte GA-Z77X-UD5H
                          Memory: 2x4GB Corsair Dominator
                          Graphics Card: MSI R7770
                          Monitor: Dell 2208WFP
                          Mouse: Mionix NAOS 5000
                          PSU: Corsair 520HX
                          Case: Thermaltake Mozart TX
                          Cooling: Thermalright TRUE Black Ultra-120 eXtreme CPU Heatsink Rev C
                          Hard Drives: 1x180 GB Intel 330 SSD - 1xWD 1 TB Caviar Black - 1xWD 2 TB Caviar Green - 2xWD 3 TB Caviar Green

                          Comment


                            #43
                            Maybe What is the difference between “else if” and “elif” in bash?
                            Windows no longer obstructs my view.
                            Using Kubuntu Linux since March 23, 2007.
                            "It is a capital mistake to theorize before one has data." - Sherlock Holmes

                            Comment


                              #44
                              We are long past that at this point. Check back a page or two.
                              OS: Kubuntu 12.10/Windows 8
                              CPU: Intel Core i7 2600K
                              Motherboard: Gigabyte GA-Z77X-UD5H
                              Memory: 2x4GB Corsair Dominator
                              Graphics Card: MSI R7770
                              Monitor: Dell 2208WFP
                              Mouse: Mionix NAOS 5000
                              PSU: Corsair 520HX
                              Case: Thermaltake Mozart TX
                              Cooling: Thermalright TRUE Black Ultra-120 eXtreme CPU Heatsink Rev C
                              Hard Drives: 1x180 GB Intel 330 SSD - 1xWD 1 TB Caviar Black - 1xWD 2 TB Caviar Green - 2xWD 3 TB Caviar Green

                              Comment


                                #45
                                Originally posted by Xplorer4x4 View Post
                                We are long past that at this point. Check back a page or two.
                                I suggest you create a new thread and summarise your question with what you have learned... allot has been discussed in this thread and most people wont want to reread it. It also makes sure everyone is up-to-date with the problem.

                                Comment

                                Working...
                                X