How to pass argument to subshell

Multi tool use
Multi tool use

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











up vote
0
down vote

favorite












Is it possible to pass DBNAME argument to subshell without manually writing it?



mysqldump -u USERNAME -p DBNAME > "$(date +"%Y-%m-%d_%H-%M-%S")_DBNAME.sql"






share|improve this question




















  • Similar (no dupe): unix.stackexchange.com/questions/436784/…
    – Kusalananda
    Apr 10 at 17:03














up vote
0
down vote

favorite












Is it possible to pass DBNAME argument to subshell without manually writing it?



mysqldump -u USERNAME -p DBNAME > "$(date +"%Y-%m-%d_%H-%M-%S")_DBNAME.sql"






share|improve this question




















  • Similar (no dupe): unix.stackexchange.com/questions/436784/…
    – Kusalananda
    Apr 10 at 17:03












up vote
0
down vote

favorite









up vote
0
down vote

favorite











Is it possible to pass DBNAME argument to subshell without manually writing it?



mysqldump -u USERNAME -p DBNAME > "$(date +"%Y-%m-%d_%H-%M-%S")_DBNAME.sql"






share|improve this question












Is it possible to pass DBNAME argument to subshell without manually writing it?



mysqldump -u USERNAME -p DBNAME > "$(date +"%Y-%m-%d_%H-%M-%S")_DBNAME.sql"








share|improve this question











share|improve this question




share|improve this question










asked Apr 10 at 15:15









J. Doe

11




11











  • Similar (no dupe): unix.stackexchange.com/questions/436784/…
    – Kusalananda
    Apr 10 at 17:03
















  • Similar (no dupe): unix.stackexchange.com/questions/436784/…
    – Kusalananda
    Apr 10 at 17:03















Similar (no dupe): unix.stackexchange.com/questions/436784/…
– Kusalananda
Apr 10 at 17:03




Similar (no dupe): unix.stackexchange.com/questions/436784/…
– Kusalananda
Apr 10 at 17:03










1 Answer
1






active

oldest

votes

















up vote
1
down vote













There is no sub-shell here, but a command substitution (the $(...)). If DBNAME is a variable, you can use



DBNAME=mydatabase
mysqldump -u USERNAME -p "$DBNAME" > "$(date +"%F_%H-%M-%S")_$DBNAME.sql"


or even



DBNAME=mydatabase
mysqldump -u USERNAME -p "$DBNAME" >"$(date +"%F_%H-%M-%S_$DBNAME.sql")"


or



DBNAME=mydatabase
outfilename=$(date +"%F_%H-%M-%S_$DBNAME.sql")
mysqldump -u USERNAME -p "$DBNAME" >"$outfilename"


or variations thereof.






share|improve this answer






















    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%2f436800%2fhow-to-pass-argument-to-subshell%23new-answer', 'question_page');

    );

    Post as a guest






























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    1
    down vote













    There is no sub-shell here, but a command substitution (the $(...)). If DBNAME is a variable, you can use



    DBNAME=mydatabase
    mysqldump -u USERNAME -p "$DBNAME" > "$(date +"%F_%H-%M-%S")_$DBNAME.sql"


    or even



    DBNAME=mydatabase
    mysqldump -u USERNAME -p "$DBNAME" >"$(date +"%F_%H-%M-%S_$DBNAME.sql")"


    or



    DBNAME=mydatabase
    outfilename=$(date +"%F_%H-%M-%S_$DBNAME.sql")
    mysqldump -u USERNAME -p "$DBNAME" >"$outfilename"


    or variations thereof.






    share|improve this answer


























      up vote
      1
      down vote













      There is no sub-shell here, but a command substitution (the $(...)). If DBNAME is a variable, you can use



      DBNAME=mydatabase
      mysqldump -u USERNAME -p "$DBNAME" > "$(date +"%F_%H-%M-%S")_$DBNAME.sql"


      or even



      DBNAME=mydatabase
      mysqldump -u USERNAME -p "$DBNAME" >"$(date +"%F_%H-%M-%S_$DBNAME.sql")"


      or



      DBNAME=mydatabase
      outfilename=$(date +"%F_%H-%M-%S_$DBNAME.sql")
      mysqldump -u USERNAME -p "$DBNAME" >"$outfilename"


      or variations thereof.






      share|improve this answer
























        up vote
        1
        down vote










        up vote
        1
        down vote









        There is no sub-shell here, but a command substitution (the $(...)). If DBNAME is a variable, you can use



        DBNAME=mydatabase
        mysqldump -u USERNAME -p "$DBNAME" > "$(date +"%F_%H-%M-%S")_$DBNAME.sql"


        or even



        DBNAME=mydatabase
        mysqldump -u USERNAME -p "$DBNAME" >"$(date +"%F_%H-%M-%S_$DBNAME.sql")"


        or



        DBNAME=mydatabase
        outfilename=$(date +"%F_%H-%M-%S_$DBNAME.sql")
        mysqldump -u USERNAME -p "$DBNAME" >"$outfilename"


        or variations thereof.






        share|improve this answer














        There is no sub-shell here, but a command substitution (the $(...)). If DBNAME is a variable, you can use



        DBNAME=mydatabase
        mysqldump -u USERNAME -p "$DBNAME" > "$(date +"%F_%H-%M-%S")_$DBNAME.sql"


        or even



        DBNAME=mydatabase
        mysqldump -u USERNAME -p "$DBNAME" >"$(date +"%F_%H-%M-%S_$DBNAME.sql")"


        or



        DBNAME=mydatabase
        outfilename=$(date +"%F_%H-%M-%S_$DBNAME.sql")
        mysqldump -u USERNAME -p "$DBNAME" >"$outfilename"


        or variations thereof.







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Apr 10 at 15:37

























        answered Apr 10 at 15:19









        Kusalananda

        102k13200317




        102k13200317






















             

            draft saved


            draft discarded


























             


            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f436800%2fhow-to-pass-argument-to-subshell%23new-answer', 'question_page');

            );

            Post as a guest













































































            jO3hH 8H GmXHkh5N,RmF gvKfLHgsjCL
            Xv,hs7ZLQpTgV,YPHywbEd Wqo5B4xt56IZ5KyHsSSnZjxi1gXEx1

            Popular posts from this blog

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

            How many registers does an x86_64 CPU actually have?

            Displaying single band from multi-band raster using QGIS