Zenity: get selected filename without its path











up vote
2
down vote

favorite












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
    7 hours ago










  • steeldriver yes that's it. "${file_to_copy##*/}" Thanx so much.
    – blades
    7 hours ago








  • 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
    3 hours ago












  • @WinEunuuchs2Unix done - please see below
    – steeldriver
    3 hours ago










  • Possible duplicate of Bash: get current working directory name, but not full path
    – wjandrea
    2 hours ago















up vote
2
down vote

favorite












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
    7 hours ago










  • steeldriver yes that's it. "${file_to_copy##*/}" Thanx so much.
    – blades
    7 hours ago








  • 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
    3 hours ago












  • @WinEunuuchs2Unix done - please see below
    – steeldriver
    3 hours ago










  • Possible duplicate of Bash: get current working directory name, but not full path
    – wjandrea
    2 hours ago













up vote
2
down vote

favorite









up vote
2
down vote

favorite











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 1 hour ago









Zanna

49.4k13127236




49.4k13127236










asked 7 hours ago









blades

256




256








  • 3




    Do you really need zenity to provide this natively? can you not just use "${file_to_copy##*/}" (or use the basename command)?
    – steeldriver
    7 hours ago










  • steeldriver yes that's it. "${file_to_copy##*/}" Thanx so much.
    – blades
    7 hours ago








  • 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
    3 hours ago












  • @WinEunuuchs2Unix done - please see below
    – steeldriver
    3 hours ago










  • Possible duplicate of Bash: get current working directory name, but not full path
    – wjandrea
    2 hours ago














  • 3




    Do you really need zenity to provide this natively? can you not just use "${file_to_copy##*/}" (or use the basename command)?
    – steeldriver
    7 hours ago










  • steeldriver yes that's it. "${file_to_copy##*/}" Thanx so much.
    – blades
    7 hours ago








  • 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
    3 hours ago












  • @WinEunuuchs2Unix done - please see below
    – steeldriver
    3 hours ago










  • Possible duplicate of Bash: get current working directory name, but not full path
    – wjandrea
    2 hours ago








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
7 hours ago




Do you really need zenity to provide this natively? can you not just use "${file_to_copy##*/}" (or use the basename command)?
– steeldriver
7 hours ago












steeldriver yes that's it. "${file_to_copy##*/}" Thanx so much.
– blades
7 hours ago






steeldriver yes that's it. "${file_to_copy##*/}" Thanx so much.
– blades
7 hours ago






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
3 hours ago






@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
3 hours ago














@WinEunuuchs2Unix done - please see below
– steeldriver
3 hours ago




@WinEunuuchs2Unix done - please see below
– steeldriver
3 hours ago












Possible duplicate of Bash: get current working directory name, but not full path
– wjandrea
2 hours ago




Possible duplicate of Bash: get current working directory name, but not full path
– wjandrea
2 hours ago










1 Answer
1






active

oldest

votes

















up vote
5
down vote



accepted










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',
    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








    up vote
    5
    down vote



    accepted










    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

























      up vote
      5
      down vote



      accepted










      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























        up vote
        5
        down vote



        accepted







        up vote
        5
        down vote



        accepted






        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 3 hours ago









        steeldriver

        65.3k11104176




        65.3k11104176






























            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

            Quarter-circle Tiles

            build a pushdown automaton that recognizes the reverse language of a given pushdown automaton?

            Mont Emei