Linux shell get device id from user input

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
0
down vote

favorite












Good day,



So I am working on an install script for a program that needs the device id from lsusb in it's configuration so I was thinking of doing the following:



$usblist=(lsusb)
#put the list into a array for each line.
#use the array to give the user a selection list usinging whiptail.
#from that line strip out the device id and vender id from the selected line.


The line looks as follows:



Bus 001 Device 004: ID 0665:5161 Cypress Semiconductor USB to Serial


So I want only the 9 characters after "IDspace"
Sorry I haven't gotten very far with my code but I am stuck on this and have no idea how to do what I would like to do. Please can someone help. I am very new to shell scripting







share|improve this question























    up vote
    0
    down vote

    favorite












    Good day,



    So I am working on an install script for a program that needs the device id from lsusb in it's configuration so I was thinking of doing the following:



    $usblist=(lsusb)
    #put the list into a array for each line.
    #use the array to give the user a selection list usinging whiptail.
    #from that line strip out the device id and vender id from the selected line.


    The line looks as follows:



    Bus 001 Device 004: ID 0665:5161 Cypress Semiconductor USB to Serial


    So I want only the 9 characters after "IDspace"
    Sorry I haven't gotten very far with my code but I am stuck on this and have no idea how to do what I would like to do. Please can someone help. I am very new to shell scripting







    share|improve this question





















      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      Good day,



      So I am working on an install script for a program that needs the device id from lsusb in it's configuration so I was thinking of doing the following:



      $usblist=(lsusb)
      #put the list into a array for each line.
      #use the array to give the user a selection list usinging whiptail.
      #from that line strip out the device id and vender id from the selected line.


      The line looks as follows:



      Bus 001 Device 004: ID 0665:5161 Cypress Semiconductor USB to Serial


      So I want only the 9 characters after "IDspace"
      Sorry I haven't gotten very far with my code but I am stuck on this and have no idea how to do what I would like to do. Please can someone help. I am very new to shell scripting







      share|improve this question











      Good day,



      So I am working on an install script for a program that needs the device id from lsusb in it's configuration so I was thinking of doing the following:



      $usblist=(lsusb)
      #put the list into a array for each line.
      #use the array to give the user a selection list usinging whiptail.
      #from that line strip out the device id and vender id from the selected line.


      The line looks as follows:



      Bus 001 Device 004: ID 0665:5161 Cypress Semiconductor USB to Serial


      So I want only the 9 characters after "IDspace"
      Sorry I haven't gotten very far with my code but I am stuck on this and have no idea how to do what I would like to do. Please can someone help. I am very new to shell scripting









      share|improve this question










      share|improve this question




      share|improve this question









      asked May 28 at 7:53









      Martinn Roelofse

      1




      1




















          2 Answers
          2






          active

          oldest

          votes

















          up vote
          0
          down vote













          The first errors that I see are.
          You wrote $usblist=(lsusb | awk 'print $6')



          You need to remove the $ from the start, and add a $ before the (. Some quotes will also help. i.e.



          usblist="$(lsusb | awk 'print $6')"






          share|improve this answer




























            up vote
            0
            down vote













            Just use, this uses awk to print out the 6th field which in your case is the ID of the device



            usblist="$(lsusb | awk 'print $6')"


            So you print any field you want, here are the mapping:



            • $1 : Bus

            • $2 : 001

            • $3 : Device

            • $4 : 004:

            • $5 : ID

            • $6 : 0665:5161

            • $7 : Cypress

            • $8 : Semiconductor

            • $9 : USB

            • $10 : to

            • $11 : Serial

            If you want to print more than one field , such as name , you can do like this



            usblist="$(lsusb | awk 'print $7,$8,$9')"





            share|improve this answer























            • You did not test this.
              – ctrl-alt-delor
              May 28 at 11:24










            • Thanks for pointing that out, I corrected it @ctrl-alt-delor
              – Arushix
              May 29 at 3:27










            Your Answer







            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "106"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            convertImagesToLinks: false,
            noModals: false,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: null,
            bindNavPrevention: true,
            postfix: "",
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );








             

            draft saved


            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f446432%2flinux-shell-get-device-id-from-user-input%23new-answer', 'question_page');

            );

            Post as a guest






























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            0
            down vote













            The first errors that I see are.
            You wrote $usblist=(lsusb | awk 'print $6')



            You need to remove the $ from the start, and add a $ before the (. Some quotes will also help. i.e.



            usblist="$(lsusb | awk 'print $6')"






            share|improve this answer

























              up vote
              0
              down vote













              The first errors that I see are.
              You wrote $usblist=(lsusb | awk 'print $6')



              You need to remove the $ from the start, and add a $ before the (. Some quotes will also help. i.e.



              usblist="$(lsusb | awk 'print $6')"






              share|improve this answer























                up vote
                0
                down vote










                up vote
                0
                down vote









                The first errors that I see are.
                You wrote $usblist=(lsusb | awk 'print $6')



                You need to remove the $ from the start, and add a $ before the (. Some quotes will also help. i.e.



                usblist="$(lsusb | awk 'print $6')"






                share|improve this answer













                The first errors that I see are.
                You wrote $usblist=(lsusb | awk 'print $6')



                You need to remove the $ from the start, and add a $ before the (. Some quotes will also help. i.e.



                usblist="$(lsusb | awk 'print $6')"







                share|improve this answer













                share|improve this answer



                share|improve this answer











                answered May 28 at 11:23









                ctrl-alt-delor

                8,75831947




                8,75831947






















                    up vote
                    0
                    down vote













                    Just use, this uses awk to print out the 6th field which in your case is the ID of the device



                    usblist="$(lsusb | awk 'print $6')"


                    So you print any field you want, here are the mapping:



                    • $1 : Bus

                    • $2 : 001

                    • $3 : Device

                    • $4 : 004:

                    • $5 : ID

                    • $6 : 0665:5161

                    • $7 : Cypress

                    • $8 : Semiconductor

                    • $9 : USB

                    • $10 : to

                    • $11 : Serial

                    If you want to print more than one field , such as name , you can do like this



                    usblist="$(lsusb | awk 'print $7,$8,$9')"





                    share|improve this answer























                    • You did not test this.
                      – ctrl-alt-delor
                      May 28 at 11:24










                    • Thanks for pointing that out, I corrected it @ctrl-alt-delor
                      – Arushix
                      May 29 at 3:27














                    up vote
                    0
                    down vote













                    Just use, this uses awk to print out the 6th field which in your case is the ID of the device



                    usblist="$(lsusb | awk 'print $6')"


                    So you print any field you want, here are the mapping:



                    • $1 : Bus

                    • $2 : 001

                    • $3 : Device

                    • $4 : 004:

                    • $5 : ID

                    • $6 : 0665:5161

                    • $7 : Cypress

                    • $8 : Semiconductor

                    • $9 : USB

                    • $10 : to

                    • $11 : Serial

                    If you want to print more than one field , such as name , you can do like this



                    usblist="$(lsusb | awk 'print $7,$8,$9')"





                    share|improve this answer























                    • You did not test this.
                      – ctrl-alt-delor
                      May 28 at 11:24










                    • Thanks for pointing that out, I corrected it @ctrl-alt-delor
                      – Arushix
                      May 29 at 3:27












                    up vote
                    0
                    down vote










                    up vote
                    0
                    down vote









                    Just use, this uses awk to print out the 6th field which in your case is the ID of the device



                    usblist="$(lsusb | awk 'print $6')"


                    So you print any field you want, here are the mapping:



                    • $1 : Bus

                    • $2 : 001

                    • $3 : Device

                    • $4 : 004:

                    • $5 : ID

                    • $6 : 0665:5161

                    • $7 : Cypress

                    • $8 : Semiconductor

                    • $9 : USB

                    • $10 : to

                    • $11 : Serial

                    If you want to print more than one field , such as name , you can do like this



                    usblist="$(lsusb | awk 'print $7,$8,$9')"





                    share|improve this answer















                    Just use, this uses awk to print out the 6th field which in your case is the ID of the device



                    usblist="$(lsusb | awk 'print $6')"


                    So you print any field you want, here are the mapping:



                    • $1 : Bus

                    • $2 : 001

                    • $3 : Device

                    • $4 : 004:

                    • $5 : ID

                    • $6 : 0665:5161

                    • $7 : Cypress

                    • $8 : Semiconductor

                    • $9 : USB

                    • $10 : to

                    • $11 : Serial

                    If you want to print more than one field , such as name , you can do like this



                    usblist="$(lsusb | awk 'print $7,$8,$9')"






                    share|improve this answer















                    share|improve this answer



                    share|improve this answer








                    edited May 29 at 3:21


























                    answered May 28 at 7:56









                    Arushix

                    9968




                    9968











                    • You did not test this.
                      – ctrl-alt-delor
                      May 28 at 11:24










                    • Thanks for pointing that out, I corrected it @ctrl-alt-delor
                      – Arushix
                      May 29 at 3:27
















                    • You did not test this.
                      – ctrl-alt-delor
                      May 28 at 11:24










                    • Thanks for pointing that out, I corrected it @ctrl-alt-delor
                      – Arushix
                      May 29 at 3:27















                    You did not test this.
                    – ctrl-alt-delor
                    May 28 at 11:24




                    You did not test this.
                    – ctrl-alt-delor
                    May 28 at 11:24












                    Thanks for pointing that out, I corrected it @ctrl-alt-delor
                    – Arushix
                    May 29 at 3:27




                    Thanks for pointing that out, I corrected it @ctrl-alt-delor
                    – Arushix
                    May 29 at 3:27












                     

                    draft saved


                    draft discarded


























                     


                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f446432%2flinux-shell-get-device-id-from-user-input%23new-answer', 'question_page');

                    );

                    Post as a guest













































































                    Popular posts from this blog

                    How to check contact read email or not when send email to Individual?

                    Bahrain

                    Postfix configuration issue with fips on centos 7; mailgun relay