How to set variables in Fish shell?










-1















The set command in my fish shell in Ubuntu (elementary OS and Linux Mint) doesn't work. The variables stay empty and even the examples in the tutorials don't work, i.e.:




(set foo hi --> # Sets the value of the variable $foo to be 'hi'.).




In the script I am trying to do the following,



set COUNTRY US CN MX


but when I want to call the variable by $COUNTRY there is no answer.



What am I doing wrong?










share|improve this question



















  • 1





    Are you sure you are running fish? E.g. dash and bash will accept set COUNTRY US CN MX without an error, but will do something entirely different. If this is a script, please check that you haven't added a #!/bin/sh shebang out of habit!

    – faho
    Nov 14 '18 at 8:45











  • In general, more context would be quite helpful here!

    – faho
    Nov 14 '18 at 8:46











  • Please read stackoverflow.com/help/how-to-ask

    – glenn jackman
    Nov 14 '18 at 15:07















-1















The set command in my fish shell in Ubuntu (elementary OS and Linux Mint) doesn't work. The variables stay empty and even the examples in the tutorials don't work, i.e.:




(set foo hi --> # Sets the value of the variable $foo to be 'hi'.).




In the script I am trying to do the following,



set COUNTRY US CN MX


but when I want to call the variable by $COUNTRY there is no answer.



What am I doing wrong?










share|improve this question



















  • 1





    Are you sure you are running fish? E.g. dash and bash will accept set COUNTRY US CN MX without an error, but will do something entirely different. If this is a script, please check that you haven't added a #!/bin/sh shebang out of habit!

    – faho
    Nov 14 '18 at 8:45











  • In general, more context would be quite helpful here!

    – faho
    Nov 14 '18 at 8:46











  • Please read stackoverflow.com/help/how-to-ask

    – glenn jackman
    Nov 14 '18 at 15:07













-1












-1








-1








The set command in my fish shell in Ubuntu (elementary OS and Linux Mint) doesn't work. The variables stay empty and even the examples in the tutorials don't work, i.e.:




(set foo hi --> # Sets the value of the variable $foo to be 'hi'.).




In the script I am trying to do the following,



set COUNTRY US CN MX


but when I want to call the variable by $COUNTRY there is no answer.



What am I doing wrong?










share|improve this question
















The set command in my fish shell in Ubuntu (elementary OS and Linux Mint) doesn't work. The variables stay empty and even the examples in the tutorials don't work, i.e.:




(set foo hi --> # Sets the value of the variable $foo to be 'hi'.).




In the script I am trying to do the following,



set COUNTRY US CN MX


but when I want to call the variable by $COUNTRY there is no answer.



What am I doing wrong?







linux ubuntu-16.04 fish






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 14 '18 at 23:35









jww

53.1k39226499




53.1k39226499










asked Nov 14 '18 at 3:17









user10649607user10649607

1




1







  • 1





    Are you sure you are running fish? E.g. dash and bash will accept set COUNTRY US CN MX without an error, but will do something entirely different. If this is a script, please check that you haven't added a #!/bin/sh shebang out of habit!

    – faho
    Nov 14 '18 at 8:45











  • In general, more context would be quite helpful here!

    – faho
    Nov 14 '18 at 8:46











  • Please read stackoverflow.com/help/how-to-ask

    – glenn jackman
    Nov 14 '18 at 15:07












  • 1





    Are you sure you are running fish? E.g. dash and bash will accept set COUNTRY US CN MX without an error, but will do something entirely different. If this is a script, please check that you haven't added a #!/bin/sh shebang out of habit!

    – faho
    Nov 14 '18 at 8:45











  • In general, more context would be quite helpful here!

    – faho
    Nov 14 '18 at 8:46











  • Please read stackoverflow.com/help/how-to-ask

    – glenn jackman
    Nov 14 '18 at 15:07







1




1





Are you sure you are running fish? E.g. dash and bash will accept set COUNTRY US CN MX without an error, but will do something entirely different. If this is a script, please check that you haven't added a #!/bin/sh shebang out of habit!

– faho
Nov 14 '18 at 8:45





Are you sure you are running fish? E.g. dash and bash will accept set COUNTRY US CN MX without an error, but will do something entirely different. If this is a script, please check that you haven't added a #!/bin/sh shebang out of habit!

– faho
Nov 14 '18 at 8:45













In general, more context would be quite helpful here!

– faho
Nov 14 '18 at 8:46





In general, more context would be quite helpful here!

– faho
Nov 14 '18 at 8:46













Please read stackoverflow.com/help/how-to-ask

– glenn jackman
Nov 14 '18 at 15:07





Please read stackoverflow.com/help/how-to-ask

– glenn jackman
Nov 14 '18 at 15:07












1 Answer
1






active

oldest

votes


















1














Are you really using the fish shell? Because your example works for me:



$ set COUNTRY US CN MX
$ echo $COUNTRY
US CN MX
$ set --show COUNTRY
$COUNTRY: not set in local scope
$COUNTRY: set in global scope, unexported, with 3 elements
$COUNTRY[1]: length=2 value=|US|
$COUNTRY[2]: length=2 value=|CN|
$COUNTRY[3]: length=2 value=|MX|
$COUNTRY: not set in universal scope


I suspect you are trying to use COUNTRY in another process. In which case you need to export the var using set -x COUNTRY US CN MX. But note that fish vars are arrays and exporting a var with more than one value won't be intelligible to a child process (unless that child process is a fish shell).



Also, it sounds like you might be trying to modify a variable in a parent process via a fish script. That won't work. You cannot modify the variables of a parent process. Not even if they are an environment variable. This is not a fish limitation. It is inherent in the design of the UNIX process model.






share|improve this answer






















    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    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%2fstackoverflow.com%2fquestions%2f53292693%2fhow-to-set-variables-in-fish-shell%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









    1














    Are you really using the fish shell? Because your example works for me:



    $ set COUNTRY US CN MX
    $ echo $COUNTRY
    US CN MX
    $ set --show COUNTRY
    $COUNTRY: not set in local scope
    $COUNTRY: set in global scope, unexported, with 3 elements
    $COUNTRY[1]: length=2 value=|US|
    $COUNTRY[2]: length=2 value=|CN|
    $COUNTRY[3]: length=2 value=|MX|
    $COUNTRY: not set in universal scope


    I suspect you are trying to use COUNTRY in another process. In which case you need to export the var using set -x COUNTRY US CN MX. But note that fish vars are arrays and exporting a var with more than one value won't be intelligible to a child process (unless that child process is a fish shell).



    Also, it sounds like you might be trying to modify a variable in a parent process via a fish script. That won't work. You cannot modify the variables of a parent process. Not even if they are an environment variable. This is not a fish limitation. It is inherent in the design of the UNIX process model.






    share|improve this answer



























      1














      Are you really using the fish shell? Because your example works for me:



      $ set COUNTRY US CN MX
      $ echo $COUNTRY
      US CN MX
      $ set --show COUNTRY
      $COUNTRY: not set in local scope
      $COUNTRY: set in global scope, unexported, with 3 elements
      $COUNTRY[1]: length=2 value=|US|
      $COUNTRY[2]: length=2 value=|CN|
      $COUNTRY[3]: length=2 value=|MX|
      $COUNTRY: not set in universal scope


      I suspect you are trying to use COUNTRY in another process. In which case you need to export the var using set -x COUNTRY US CN MX. But note that fish vars are arrays and exporting a var with more than one value won't be intelligible to a child process (unless that child process is a fish shell).



      Also, it sounds like you might be trying to modify a variable in a parent process via a fish script. That won't work. You cannot modify the variables of a parent process. Not even if they are an environment variable. This is not a fish limitation. It is inherent in the design of the UNIX process model.






      share|improve this answer

























        1












        1








        1







        Are you really using the fish shell? Because your example works for me:



        $ set COUNTRY US CN MX
        $ echo $COUNTRY
        US CN MX
        $ set --show COUNTRY
        $COUNTRY: not set in local scope
        $COUNTRY: set in global scope, unexported, with 3 elements
        $COUNTRY[1]: length=2 value=|US|
        $COUNTRY[2]: length=2 value=|CN|
        $COUNTRY[3]: length=2 value=|MX|
        $COUNTRY: not set in universal scope


        I suspect you are trying to use COUNTRY in another process. In which case you need to export the var using set -x COUNTRY US CN MX. But note that fish vars are arrays and exporting a var with more than one value won't be intelligible to a child process (unless that child process is a fish shell).



        Also, it sounds like you might be trying to modify a variable in a parent process via a fish script. That won't work. You cannot modify the variables of a parent process. Not even if they are an environment variable. This is not a fish limitation. It is inherent in the design of the UNIX process model.






        share|improve this answer













        Are you really using the fish shell? Because your example works for me:



        $ set COUNTRY US CN MX
        $ echo $COUNTRY
        US CN MX
        $ set --show COUNTRY
        $COUNTRY: not set in local scope
        $COUNTRY: set in global scope, unexported, with 3 elements
        $COUNTRY[1]: length=2 value=|US|
        $COUNTRY[2]: length=2 value=|CN|
        $COUNTRY[3]: length=2 value=|MX|
        $COUNTRY: not set in universal scope


        I suspect you are trying to use COUNTRY in another process. In which case you need to export the var using set -x COUNTRY US CN MX. But note that fish vars are arrays and exporting a var with more than one value won't be intelligible to a child process (unless that child process is a fish shell).



        Also, it sounds like you might be trying to modify a variable in a parent process via a fish script. That won't work. You cannot modify the variables of a parent process. Not even if they are an environment variable. This is not a fish limitation. It is inherent in the design of the UNIX process model.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 14 '18 at 5:07









        Kurtis RaderKurtis Rader

        3,104610




        3,104610



























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • 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%2fstackoverflow.com%2fquestions%2f53292693%2fhow-to-set-variables-in-fish-shell%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







            這個網誌中的熱門文章

            How to read a connectionString WITH PROVIDER in .NET Core?

            In R, how to develop a multiplot heatmap.2 figure showing key labels successfully

            Museum of Modern and Contemporary Art of Trento and Rovereto