First argument passed to wrapper script is ignored

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











up vote
2
down vote

favorite












So I've got the following script:



#!/bin/bash

echo '-------------------------'
echo $0
echo $1
echo $@
echo '-------------------------'

exec su -- someuser -c "/tmp/elasticsearch-6.4.2/bin/elasticsearch "$@""


Located at /usr/bin/elasticsearch-wrapper



Now when I run it with the following args:



elasticsearch-wrapper 
-E cluster.name=elasticsearch-test-24efcbba4c68
-E node.name=node-1
-E http.port=9250
-E path.data=/tmp/elasticsearch_test
-E path.logs=/tmp/log/elasticsearch
-E cluster.routing.allocation.disk.threshold_enabled=false
-E network.host=127.0.0.1
-E node.attr.testattr=test
-E path.repo=/tmp
-E repositories.url.allowed_urls=http://snapshot.test*
-E discovery.zen.minimum_master_nodes=0
-E node.max_local_storage_nodes=1
-E logger.level=DEBUG


I end up with the following error:



root@24efcbba4c68:/app# elasticsearch-wrapper 
> -E cluster.name=elasticsearch-test-24efcbba4c68
> -E node.name=node-1
> -E http.port=9250
> -E path.data=/tmp/elasticsearch_test
> -E path.logs=/tmp/log/elasticsearch
> -E cluster.routing.allocation.disk.threshold_enabled=false
> -E network.host=127.0.0.1
> -E node.attr.testattr=test
> -E path.repo=/tmp
> -E repositories.url.allowed_urls=http://snapshot.test*
> -E discovery.zen.minimum_master_nodes=0
> -E node.max_local_storage_nodes=1
> -E logger.level=DEBUG
-------------------------
/usr/bin/elasticsearch-wrapper

cluster.name=elasticsearch-test-24efcbba4c68 -E node.name=node-1 -E http.port=9250 -E path.data=/tmp/elasticsearch_test -E path.logs=/tmp/log/elasticsearch -E cluster.routing.allocation.disk.threshold_enabled=false -E network.host=127.0.0.1 -E node.attr.testattr=test -E path.repo=/tmp -E repositories.url.allowed_urls=http://snapshot.test* -E discovery.zen.minimum_master_nodes=0 -E node.max_local_storage_nodes=1 -E logger.level=DEBUG
-------------------------
cluster.name=elasticsearch-test-24efcbba4c68: -c: line 0: unexpected EOF while looking for matching `"'
cluster.name=elasticsearch-test-24efcbba4c68: -c: line 1: syntax error: unexpected end of file


So looking at the output of $@ shows that the first -E option is for some reason excluded which results in the error.



The output was:



cluster.name=elasticsearch-test-24efcbba4c68 -E node.name=node-1.....



but it should be:



-E cluster.name=elasticsearch-test-24efcbba4c68 -E node.name=node-1....



(Notice the missing -E from the start)



But I'm not sure why that is the case if anyone could point out the reason?










share|improve this question









New contributor




kurupt_89 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.



















  • See also: unix.stackexchange.com/q/65803/117549
    – Jeff Schaller
    4 hours ago














up vote
2
down vote

favorite












So I've got the following script:



#!/bin/bash

echo '-------------------------'
echo $0
echo $1
echo $@
echo '-------------------------'

exec su -- someuser -c "/tmp/elasticsearch-6.4.2/bin/elasticsearch "$@""


Located at /usr/bin/elasticsearch-wrapper



Now when I run it with the following args:



elasticsearch-wrapper 
-E cluster.name=elasticsearch-test-24efcbba4c68
-E node.name=node-1
-E http.port=9250
-E path.data=/tmp/elasticsearch_test
-E path.logs=/tmp/log/elasticsearch
-E cluster.routing.allocation.disk.threshold_enabled=false
-E network.host=127.0.0.1
-E node.attr.testattr=test
-E path.repo=/tmp
-E repositories.url.allowed_urls=http://snapshot.test*
-E discovery.zen.minimum_master_nodes=0
-E node.max_local_storage_nodes=1
-E logger.level=DEBUG


I end up with the following error:



root@24efcbba4c68:/app# elasticsearch-wrapper 
> -E cluster.name=elasticsearch-test-24efcbba4c68
> -E node.name=node-1
> -E http.port=9250
> -E path.data=/tmp/elasticsearch_test
> -E path.logs=/tmp/log/elasticsearch
> -E cluster.routing.allocation.disk.threshold_enabled=false
> -E network.host=127.0.0.1
> -E node.attr.testattr=test
> -E path.repo=/tmp
> -E repositories.url.allowed_urls=http://snapshot.test*
> -E discovery.zen.minimum_master_nodes=0
> -E node.max_local_storage_nodes=1
> -E logger.level=DEBUG
-------------------------
/usr/bin/elasticsearch-wrapper

cluster.name=elasticsearch-test-24efcbba4c68 -E node.name=node-1 -E http.port=9250 -E path.data=/tmp/elasticsearch_test -E path.logs=/tmp/log/elasticsearch -E cluster.routing.allocation.disk.threshold_enabled=false -E network.host=127.0.0.1 -E node.attr.testattr=test -E path.repo=/tmp -E repositories.url.allowed_urls=http://snapshot.test* -E discovery.zen.minimum_master_nodes=0 -E node.max_local_storage_nodes=1 -E logger.level=DEBUG
-------------------------
cluster.name=elasticsearch-test-24efcbba4c68: -c: line 0: unexpected EOF while looking for matching `"'
cluster.name=elasticsearch-test-24efcbba4c68: -c: line 1: syntax error: unexpected end of file


So looking at the output of $@ shows that the first -E option is for some reason excluded which results in the error.



The output was:



cluster.name=elasticsearch-test-24efcbba4c68 -E node.name=node-1.....



but it should be:



-E cluster.name=elasticsearch-test-24efcbba4c68 -E node.name=node-1....



(Notice the missing -E from the start)



But I'm not sure why that is the case if anyone could point out the reason?










share|improve this question









New contributor




kurupt_89 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.



















  • See also: unix.stackexchange.com/q/65803/117549
    – Jeff Schaller
    4 hours ago












up vote
2
down vote

favorite









up vote
2
down vote

favorite











So I've got the following script:



#!/bin/bash

echo '-------------------------'
echo $0
echo $1
echo $@
echo '-------------------------'

exec su -- someuser -c "/tmp/elasticsearch-6.4.2/bin/elasticsearch "$@""


Located at /usr/bin/elasticsearch-wrapper



Now when I run it with the following args:



elasticsearch-wrapper 
-E cluster.name=elasticsearch-test-24efcbba4c68
-E node.name=node-1
-E http.port=9250
-E path.data=/tmp/elasticsearch_test
-E path.logs=/tmp/log/elasticsearch
-E cluster.routing.allocation.disk.threshold_enabled=false
-E network.host=127.0.0.1
-E node.attr.testattr=test
-E path.repo=/tmp
-E repositories.url.allowed_urls=http://snapshot.test*
-E discovery.zen.minimum_master_nodes=0
-E node.max_local_storage_nodes=1
-E logger.level=DEBUG


I end up with the following error:



root@24efcbba4c68:/app# elasticsearch-wrapper 
> -E cluster.name=elasticsearch-test-24efcbba4c68
> -E node.name=node-1
> -E http.port=9250
> -E path.data=/tmp/elasticsearch_test
> -E path.logs=/tmp/log/elasticsearch
> -E cluster.routing.allocation.disk.threshold_enabled=false
> -E network.host=127.0.0.1
> -E node.attr.testattr=test
> -E path.repo=/tmp
> -E repositories.url.allowed_urls=http://snapshot.test*
> -E discovery.zen.minimum_master_nodes=0
> -E node.max_local_storage_nodes=1
> -E logger.level=DEBUG
-------------------------
/usr/bin/elasticsearch-wrapper

cluster.name=elasticsearch-test-24efcbba4c68 -E node.name=node-1 -E http.port=9250 -E path.data=/tmp/elasticsearch_test -E path.logs=/tmp/log/elasticsearch -E cluster.routing.allocation.disk.threshold_enabled=false -E network.host=127.0.0.1 -E node.attr.testattr=test -E path.repo=/tmp -E repositories.url.allowed_urls=http://snapshot.test* -E discovery.zen.minimum_master_nodes=0 -E node.max_local_storage_nodes=1 -E logger.level=DEBUG
-------------------------
cluster.name=elasticsearch-test-24efcbba4c68: -c: line 0: unexpected EOF while looking for matching `"'
cluster.name=elasticsearch-test-24efcbba4c68: -c: line 1: syntax error: unexpected end of file


So looking at the output of $@ shows that the first -E option is for some reason excluded which results in the error.



The output was:



cluster.name=elasticsearch-test-24efcbba4c68 -E node.name=node-1.....



but it should be:



-E cluster.name=elasticsearch-test-24efcbba4c68 -E node.name=node-1....



(Notice the missing -E from the start)



But I'm not sure why that is the case if anyone could point out the reason?










share|improve this question









New contributor




kurupt_89 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











So I've got the following script:



#!/bin/bash

echo '-------------------------'
echo $0
echo $1
echo $@
echo '-------------------------'

exec su -- someuser -c "/tmp/elasticsearch-6.4.2/bin/elasticsearch "$@""


Located at /usr/bin/elasticsearch-wrapper



Now when I run it with the following args:



elasticsearch-wrapper 
-E cluster.name=elasticsearch-test-24efcbba4c68
-E node.name=node-1
-E http.port=9250
-E path.data=/tmp/elasticsearch_test
-E path.logs=/tmp/log/elasticsearch
-E cluster.routing.allocation.disk.threshold_enabled=false
-E network.host=127.0.0.1
-E node.attr.testattr=test
-E path.repo=/tmp
-E repositories.url.allowed_urls=http://snapshot.test*
-E discovery.zen.minimum_master_nodes=0
-E node.max_local_storage_nodes=1
-E logger.level=DEBUG


I end up with the following error:



root@24efcbba4c68:/app# elasticsearch-wrapper 
> -E cluster.name=elasticsearch-test-24efcbba4c68
> -E node.name=node-1
> -E http.port=9250
> -E path.data=/tmp/elasticsearch_test
> -E path.logs=/tmp/log/elasticsearch
> -E cluster.routing.allocation.disk.threshold_enabled=false
> -E network.host=127.0.0.1
> -E node.attr.testattr=test
> -E path.repo=/tmp
> -E repositories.url.allowed_urls=http://snapshot.test*
> -E discovery.zen.minimum_master_nodes=0
> -E node.max_local_storage_nodes=1
> -E logger.level=DEBUG
-------------------------
/usr/bin/elasticsearch-wrapper

cluster.name=elasticsearch-test-24efcbba4c68 -E node.name=node-1 -E http.port=9250 -E path.data=/tmp/elasticsearch_test -E path.logs=/tmp/log/elasticsearch -E cluster.routing.allocation.disk.threshold_enabled=false -E network.host=127.0.0.1 -E node.attr.testattr=test -E path.repo=/tmp -E repositories.url.allowed_urls=http://snapshot.test* -E discovery.zen.minimum_master_nodes=0 -E node.max_local_storage_nodes=1 -E logger.level=DEBUG
-------------------------
cluster.name=elasticsearch-test-24efcbba4c68: -c: line 0: unexpected EOF while looking for matching `"'
cluster.name=elasticsearch-test-24efcbba4c68: -c: line 1: syntax error: unexpected end of file


So looking at the output of $@ shows that the first -E option is for some reason excluded which results in the error.



The output was:



cluster.name=elasticsearch-test-24efcbba4c68 -E node.name=node-1.....



but it should be:



-E cluster.name=elasticsearch-test-24efcbba4c68 -E node.name=node-1....



(Notice the missing -E from the start)



But I'm not sure why that is the case if anyone could point out the reason?







bash shell-script arguments






share|improve this question









New contributor




kurupt_89 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question









New contributor




kurupt_89 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question








edited 6 hours ago





















New contributor




kurupt_89 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked 6 hours ago









kurupt_89

11115




11115




New contributor




kurupt_89 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





kurupt_89 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






kurupt_89 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











  • See also: unix.stackexchange.com/q/65803/117549
    – Jeff Schaller
    4 hours ago
















  • See also: unix.stackexchange.com/q/65803/117549
    – Jeff Schaller
    4 hours ago















See also: unix.stackexchange.com/q/65803/117549
– Jeff Schaller
4 hours ago




See also: unix.stackexchange.com/q/65803/117549
– Jeff Schaller
4 hours ago










2 Answers
2






active

oldest

votes

















up vote
2
down vote













The reason why echo $1 prints an empty line in your case where $1 expands to -E is that echo is taking -E as a flag and interpreting it as a modifier rather as something to print.



Use printf instead, which is able to reliably print arguments with arbitrary contents:



printf "%sn" "$1"
printf "%sn" "$*"


The last line where you're executing elasticsearch under su -c, you can't really use $@, since it expands to multiple arguments inside double quotes and su -c expects a single argument to pass to a shell. So you should use $* here, without any quotes.



exec su someuser -c "/tmp/elasticsearch-6.4.2/bin/elasticsearch $*"


That's imperfect, since it will do another round of shell substitution on your arguments, so if there's any meta-characters in the arguments you might run into trouble...



If your distribution ships with a command such as runas or runuser, which takes the command as multiple arguments, that's a better choice than su, not only for that reason but also in how the PAM stack is used (su is really meant for interactive use rather than spawning services.) Or if you're spawning this service using something like systemd, then switching users in the service file would be best.






share|improve this answer


















  • 2




    That -- just echos -- on my bash. I would use printf "%s" "$1"
    – ctrl-alt-delor
    2 hours ago







  • 2




    not only in bash. The standard is quite clear that echo should always treat -- as an ordinary argument.
    – mosvy
    50 mins ago










  • @ctrl-alt-delor Updated to recommend use of printf instead.
    – Filipe Brandenburger
    12 mins ago

















up vote
2
down vote













replace your last line with:



exec su -c '/tmp/elasticsearch-6.4.2/bin/elasticsearch "$@"' someuser -- dummy-argv0 "$@"


su's synopsis in the man page (su [options] [username]) is deceptive, here is some verbiage from below it:




Additional arguments may be provided after the username, in which case they are supplied to the user's login shell.



....



You can use the -- argument to separate su options from the arguments
supplied to the shell.




You should also replace all the echos with printf '%sn' ..., since the echo builtin from bash and zsh, and /bin/echo from linux will use themselves the -E argument (quite contrary to what the standard requires). Generally, there's no way to safely use echo with variables which may expand to -n, -e or -E.






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: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    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
    );



    );






    kurupt_89 is a new contributor. Be nice, and check out our Code of Conduct.









     

    draft saved


    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f479587%2ffirst-argument-passed-to-wrapper-script-is-ignored%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
    2
    down vote













    The reason why echo $1 prints an empty line in your case where $1 expands to -E is that echo is taking -E as a flag and interpreting it as a modifier rather as something to print.



    Use printf instead, which is able to reliably print arguments with arbitrary contents:



    printf "%sn" "$1"
    printf "%sn" "$*"


    The last line where you're executing elasticsearch under su -c, you can't really use $@, since it expands to multiple arguments inside double quotes and su -c expects a single argument to pass to a shell. So you should use $* here, without any quotes.



    exec su someuser -c "/tmp/elasticsearch-6.4.2/bin/elasticsearch $*"


    That's imperfect, since it will do another round of shell substitution on your arguments, so if there's any meta-characters in the arguments you might run into trouble...



    If your distribution ships with a command such as runas or runuser, which takes the command as multiple arguments, that's a better choice than su, not only for that reason but also in how the PAM stack is used (su is really meant for interactive use rather than spawning services.) Or if you're spawning this service using something like systemd, then switching users in the service file would be best.






    share|improve this answer


















    • 2




      That -- just echos -- on my bash. I would use printf "%s" "$1"
      – ctrl-alt-delor
      2 hours ago







    • 2




      not only in bash. The standard is quite clear that echo should always treat -- as an ordinary argument.
      – mosvy
      50 mins ago










    • @ctrl-alt-delor Updated to recommend use of printf instead.
      – Filipe Brandenburger
      12 mins ago














    up vote
    2
    down vote













    The reason why echo $1 prints an empty line in your case where $1 expands to -E is that echo is taking -E as a flag and interpreting it as a modifier rather as something to print.



    Use printf instead, which is able to reliably print arguments with arbitrary contents:



    printf "%sn" "$1"
    printf "%sn" "$*"


    The last line where you're executing elasticsearch under su -c, you can't really use $@, since it expands to multiple arguments inside double quotes and su -c expects a single argument to pass to a shell. So you should use $* here, without any quotes.



    exec su someuser -c "/tmp/elasticsearch-6.4.2/bin/elasticsearch $*"


    That's imperfect, since it will do another round of shell substitution on your arguments, so if there's any meta-characters in the arguments you might run into trouble...



    If your distribution ships with a command such as runas or runuser, which takes the command as multiple arguments, that's a better choice than su, not only for that reason but also in how the PAM stack is used (su is really meant for interactive use rather than spawning services.) Or if you're spawning this service using something like systemd, then switching users in the service file would be best.






    share|improve this answer


















    • 2




      That -- just echos -- on my bash. I would use printf "%s" "$1"
      – ctrl-alt-delor
      2 hours ago







    • 2




      not only in bash. The standard is quite clear that echo should always treat -- as an ordinary argument.
      – mosvy
      50 mins ago










    • @ctrl-alt-delor Updated to recommend use of printf instead.
      – Filipe Brandenburger
      12 mins ago












    up vote
    2
    down vote










    up vote
    2
    down vote









    The reason why echo $1 prints an empty line in your case where $1 expands to -E is that echo is taking -E as a flag and interpreting it as a modifier rather as something to print.



    Use printf instead, which is able to reliably print arguments with arbitrary contents:



    printf "%sn" "$1"
    printf "%sn" "$*"


    The last line where you're executing elasticsearch under su -c, you can't really use $@, since it expands to multiple arguments inside double quotes and su -c expects a single argument to pass to a shell. So you should use $* here, without any quotes.



    exec su someuser -c "/tmp/elasticsearch-6.4.2/bin/elasticsearch $*"


    That's imperfect, since it will do another round of shell substitution on your arguments, so if there's any meta-characters in the arguments you might run into trouble...



    If your distribution ships with a command such as runas or runuser, which takes the command as multiple arguments, that's a better choice than su, not only for that reason but also in how the PAM stack is used (su is really meant for interactive use rather than spawning services.) Or if you're spawning this service using something like systemd, then switching users in the service file would be best.






    share|improve this answer














    The reason why echo $1 prints an empty line in your case where $1 expands to -E is that echo is taking -E as a flag and interpreting it as a modifier rather as something to print.



    Use printf instead, which is able to reliably print arguments with arbitrary contents:



    printf "%sn" "$1"
    printf "%sn" "$*"


    The last line where you're executing elasticsearch under su -c, you can't really use $@, since it expands to multiple arguments inside double quotes and su -c expects a single argument to pass to a shell. So you should use $* here, without any quotes.



    exec su someuser -c "/tmp/elasticsearch-6.4.2/bin/elasticsearch $*"


    That's imperfect, since it will do another round of shell substitution on your arguments, so if there's any meta-characters in the arguments you might run into trouble...



    If your distribution ships with a command such as runas or runuser, which takes the command as multiple arguments, that's a better choice than su, not only for that reason but also in how the PAM stack is used (su is really meant for interactive use rather than spawning services.) Or if you're spawning this service using something like systemd, then switching users in the service file would be best.







    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited 13 mins ago

























    answered 4 hours ago









    Filipe Brandenburger

    4,8001623




    4,8001623







    • 2




      That -- just echos -- on my bash. I would use printf "%s" "$1"
      – ctrl-alt-delor
      2 hours ago







    • 2




      not only in bash. The standard is quite clear that echo should always treat -- as an ordinary argument.
      – mosvy
      50 mins ago










    • @ctrl-alt-delor Updated to recommend use of printf instead.
      – Filipe Brandenburger
      12 mins ago












    • 2




      That -- just echos -- on my bash. I would use printf "%s" "$1"
      – ctrl-alt-delor
      2 hours ago







    • 2




      not only in bash. The standard is quite clear that echo should always treat -- as an ordinary argument.
      – mosvy
      50 mins ago










    • @ctrl-alt-delor Updated to recommend use of printf instead.
      – Filipe Brandenburger
      12 mins ago







    2




    2




    That -- just echos -- on my bash. I would use printf "%s" "$1"
    – ctrl-alt-delor
    2 hours ago





    That -- just echos -- on my bash. I would use printf "%s" "$1"
    – ctrl-alt-delor
    2 hours ago





    2




    2




    not only in bash. The standard is quite clear that echo should always treat -- as an ordinary argument.
    – mosvy
    50 mins ago




    not only in bash. The standard is quite clear that echo should always treat -- as an ordinary argument.
    – mosvy
    50 mins ago












    @ctrl-alt-delor Updated to recommend use of printf instead.
    – Filipe Brandenburger
    12 mins ago




    @ctrl-alt-delor Updated to recommend use of printf instead.
    – Filipe Brandenburger
    12 mins ago












    up vote
    2
    down vote













    replace your last line with:



    exec su -c '/tmp/elasticsearch-6.4.2/bin/elasticsearch "$@"' someuser -- dummy-argv0 "$@"


    su's synopsis in the man page (su [options] [username]) is deceptive, here is some verbiage from below it:




    Additional arguments may be provided after the username, in which case they are supplied to the user's login shell.



    ....



    You can use the -- argument to separate su options from the arguments
    supplied to the shell.




    You should also replace all the echos with printf '%sn' ..., since the echo builtin from bash and zsh, and /bin/echo from linux will use themselves the -E argument (quite contrary to what the standard requires). Generally, there's no way to safely use echo with variables which may expand to -n, -e or -E.






    share|improve this answer


























      up vote
      2
      down vote













      replace your last line with:



      exec su -c '/tmp/elasticsearch-6.4.2/bin/elasticsearch "$@"' someuser -- dummy-argv0 "$@"


      su's synopsis in the man page (su [options] [username]) is deceptive, here is some verbiage from below it:




      Additional arguments may be provided after the username, in which case they are supplied to the user's login shell.



      ....



      You can use the -- argument to separate su options from the arguments
      supplied to the shell.




      You should also replace all the echos with printf '%sn' ..., since the echo builtin from bash and zsh, and /bin/echo from linux will use themselves the -E argument (quite contrary to what the standard requires). Generally, there's no way to safely use echo with variables which may expand to -n, -e or -E.






      share|improve this answer
























        up vote
        2
        down vote










        up vote
        2
        down vote









        replace your last line with:



        exec su -c '/tmp/elasticsearch-6.4.2/bin/elasticsearch "$@"' someuser -- dummy-argv0 "$@"


        su's synopsis in the man page (su [options] [username]) is deceptive, here is some verbiage from below it:




        Additional arguments may be provided after the username, in which case they are supplied to the user's login shell.



        ....



        You can use the -- argument to separate su options from the arguments
        supplied to the shell.




        You should also replace all the echos with printf '%sn' ..., since the echo builtin from bash and zsh, and /bin/echo from linux will use themselves the -E argument (quite contrary to what the standard requires). Generally, there's no way to safely use echo with variables which may expand to -n, -e or -E.






        share|improve this answer














        replace your last line with:



        exec su -c '/tmp/elasticsearch-6.4.2/bin/elasticsearch "$@"' someuser -- dummy-argv0 "$@"


        su's synopsis in the man page (su [options] [username]) is deceptive, here is some verbiage from below it:




        Additional arguments may be provided after the username, in which case they are supplied to the user's login shell.



        ....



        You can use the -- argument to separate su options from the arguments
        supplied to the shell.




        You should also replace all the echos with printf '%sn' ..., since the echo builtin from bash and zsh, and /bin/echo from linux will use themselves the -E argument (quite contrary to what the standard requires). Generally, there's no way to safely use echo with variables which may expand to -n, -e or -E.







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited 11 mins ago

























        answered 39 mins ago









        mosvy

        3,480119




        3,480119




















            kurupt_89 is a new contributor. Be nice, and check out our Code of Conduct.









             

            draft saved


            draft discarded


















            kurupt_89 is a new contributor. Be nice, and check out our Code of Conduct.












            kurupt_89 is a new contributor. Be nice, and check out our Code of Conduct.











            kurupt_89 is a new contributor. Be nice, and check out our Code of Conduct.













             


            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f479587%2ffirst-argument-passed-to-wrapper-script-is-ignored%23new-answer', 'question_page');

            );

            Post as a guest













































































            Comments

            Popular posts from this blog

            Long meetings (6-7 hours a day): Being “babysat” by supervisor

            What does second last employer means? [closed]

            One-line joke