Zenity: get selected filename without its path












3














I need zenity to put a selected filename into a variable without its path.
What I have now is



file_to_copy="$(zenity --file-selection --title='Select a File')"
echo $file_to_copy


then prints



/home/blades/Scripts/openwrt-vpn-renew/ze.sh


I wanted to just print ze.sh.










share|improve this question




















  • 3




    Do you really need zenity to provide this natively? can you not just use "${file_to_copy##*/}" (or use the basename command)?
    – steeldriver
    Dec 16 '18 at 11:29










  • steeldriver yes that's it. "${file_to_copy##*/}" Thanx so much.
    – blades
    Dec 16 '18 at 11:37








  • 1




    @steeldriver I wanted to close this as a duplicate but it is over on Stack Overflow: stackoverflow.com/questions/2664740/…. Could you post an answer here that can be accepted? (Ping me and I'll up-vote :))
    – WinEunuuchs2Unix
    Dec 16 '18 at 15:31












  • @WinEunuuchs2Unix done - please see below
    – steeldriver
    Dec 16 '18 at 16:06






  • 1




    Possible duplicate of Bash: get current working directory name, but not full path
    – wjandrea
    Dec 16 '18 at 17:04
















3














I need zenity to put a selected filename into a variable without its path.
What I have now is



file_to_copy="$(zenity --file-selection --title='Select a File')"
echo $file_to_copy


then prints



/home/blades/Scripts/openwrt-vpn-renew/ze.sh


I wanted to just print ze.sh.










share|improve this question




















  • 3




    Do you really need zenity to provide this natively? can you not just use "${file_to_copy##*/}" (or use the basename command)?
    – steeldriver
    Dec 16 '18 at 11:29










  • steeldriver yes that's it. "${file_to_copy##*/}" Thanx so much.
    – blades
    Dec 16 '18 at 11:37








  • 1




    @steeldriver I wanted to close this as a duplicate but it is over on Stack Overflow: stackoverflow.com/questions/2664740/…. Could you post an answer here that can be accepted? (Ping me and I'll up-vote :))
    – WinEunuuchs2Unix
    Dec 16 '18 at 15:31












  • @WinEunuuchs2Unix done - please see below
    – steeldriver
    Dec 16 '18 at 16:06






  • 1




    Possible duplicate of Bash: get current working directory name, but not full path
    – wjandrea
    Dec 16 '18 at 17:04














3












3








3







I need zenity to put a selected filename into a variable without its path.
What I have now is



file_to_copy="$(zenity --file-selection --title='Select a File')"
echo $file_to_copy


then prints



/home/blades/Scripts/openwrt-vpn-renew/ze.sh


I wanted to just print ze.sh.










share|improve this question















I need zenity to put a selected filename into a variable without its path.
What I have now is



file_to_copy="$(zenity --file-selection --title='Select a File')"
echo $file_to_copy


then prints



/home/blades/Scripts/openwrt-vpn-renew/ze.sh


I wanted to just print ze.sh.







command-line zenity






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Dec 16 '18 at 18:15









Zanna

50.3k13133241




50.3k13133241










asked Dec 16 '18 at 11:23









bladesblades

357




357








  • 3




    Do you really need zenity to provide this natively? can you not just use "${file_to_copy##*/}" (or use the basename command)?
    – steeldriver
    Dec 16 '18 at 11:29










  • steeldriver yes that's it. "${file_to_copy##*/}" Thanx so much.
    – blades
    Dec 16 '18 at 11:37








  • 1




    @steeldriver I wanted to close this as a duplicate but it is over on Stack Overflow: stackoverflow.com/questions/2664740/…. Could you post an answer here that can be accepted? (Ping me and I'll up-vote :))
    – WinEunuuchs2Unix
    Dec 16 '18 at 15:31












  • @WinEunuuchs2Unix done - please see below
    – steeldriver
    Dec 16 '18 at 16:06






  • 1




    Possible duplicate of Bash: get current working directory name, but not full path
    – wjandrea
    Dec 16 '18 at 17:04














  • 3




    Do you really need zenity to provide this natively? can you not just use "${file_to_copy##*/}" (or use the basename command)?
    – steeldriver
    Dec 16 '18 at 11:29










  • steeldriver yes that's it. "${file_to_copy##*/}" Thanx so much.
    – blades
    Dec 16 '18 at 11:37








  • 1




    @steeldriver I wanted to close this as a duplicate but it is over on Stack Overflow: stackoverflow.com/questions/2664740/…. Could you post an answer here that can be accepted? (Ping me and I'll up-vote :))
    – WinEunuuchs2Unix
    Dec 16 '18 at 15:31












  • @WinEunuuchs2Unix done - please see below
    – steeldriver
    Dec 16 '18 at 16:06






  • 1




    Possible duplicate of Bash: get current working directory name, but not full path
    – wjandrea
    Dec 16 '18 at 17:04








3




3




Do you really need zenity to provide this natively? can you not just use "${file_to_copy##*/}" (or use the basename command)?
– steeldriver
Dec 16 '18 at 11:29




Do you really need zenity to provide this natively? can you not just use "${file_to_copy##*/}" (or use the basename command)?
– steeldriver
Dec 16 '18 at 11:29












steeldriver yes that's it. "${file_to_copy##*/}" Thanx so much.
– blades
Dec 16 '18 at 11:37






steeldriver yes that's it. "${file_to_copy##*/}" Thanx so much.
– blades
Dec 16 '18 at 11:37






1




1




@steeldriver I wanted to close this as a duplicate but it is over on Stack Overflow: stackoverflow.com/questions/2664740/…. Could you post an answer here that can be accepted? (Ping me and I'll up-vote :))
– WinEunuuchs2Unix
Dec 16 '18 at 15:31






@steeldriver I wanted to close this as a duplicate but it is over on Stack Overflow: stackoverflow.com/questions/2664740/…. Could you post an answer here that can be accepted? (Ping me and I'll up-vote :))
– WinEunuuchs2Unix
Dec 16 '18 at 15:31














@WinEunuuchs2Unix done - please see below
– steeldriver
Dec 16 '18 at 16:06




@WinEunuuchs2Unix done - please see below
– steeldriver
Dec 16 '18 at 16:06




1




1




Possible duplicate of Bash: get current working directory name, but not full path
– wjandrea
Dec 16 '18 at 17:04




Possible duplicate of Bash: get current working directory name, but not full path
– wjandrea
Dec 16 '18 at 17:04










1 Answer
1






active

oldest

votes


















7














If you don't absolutely need zenity to provide this functionality for you, then you can easily do it in the shell, either using parameter expansion



file_to_copy=${file_to_copy##*/}


where ##*/ refers to the longest leading string matching */, or using the basename utility



file_to_copy=$(basename "$file_to_copy")





share|improve this answer





















    Your Answer








    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "89"
    };
    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',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1102290%2fzenity-get-selected-filename-without-its-path%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    7














    If you don't absolutely need zenity to provide this functionality for you, then you can easily do it in the shell, either using parameter expansion



    file_to_copy=${file_to_copy##*/}


    where ##*/ refers to the longest leading string matching */, or using the basename utility



    file_to_copy=$(basename "$file_to_copy")





    share|improve this answer


























      7














      If you don't absolutely need zenity to provide this functionality for you, then you can easily do it in the shell, either using parameter expansion



      file_to_copy=${file_to_copy##*/}


      where ##*/ refers to the longest leading string matching */, or using the basename utility



      file_to_copy=$(basename "$file_to_copy")





      share|improve this answer
























        7












        7








        7






        If you don't absolutely need zenity to provide this functionality for you, then you can easily do it in the shell, either using parameter expansion



        file_to_copy=${file_to_copy##*/}


        where ##*/ refers to the longest leading string matching */, or using the basename utility



        file_to_copy=$(basename "$file_to_copy")





        share|improve this answer












        If you don't absolutely need zenity to provide this functionality for you, then you can easily do it in the shell, either using parameter expansion



        file_to_copy=${file_to_copy##*/}


        where ##*/ refers to the longest leading string matching */, or using the basename utility



        file_to_copy=$(basename "$file_to_copy")






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Dec 16 '18 at 16:06









        steeldriversteeldriver

        66k11105178




        66k11105178






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Ask Ubuntu!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1102290%2fzenity-get-selected-filename-without-its-path%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            "Incorrect syntax near the keyword 'ON'. (on update cascade, on delete cascade,)

            Alcedinidae

            Origin of the phrase “under your belt”?