• Re: Shell script doesn't accept arguments (maybe OT?)

    From Kenny McCormack@21:1/5 to [email protected] on Mon Apr 3 16:05:36 2023
    In article <u0erqc$30uas$[email protected]>,
    Ottavio Caruso <[email protected]> wrote:
    Hi,

    I'm trying to narrow this down to either my script or Firefox itself.

    I have a rudimentary shell launcher:

    $ cat opt/bin/ff-accel
    #!/bin/sh
    env MOZ_X11_EGL=1 /home/oc/opt/firefox/firefox

    This needs to be:

    env MOZ_X11_EGL=1 /home/oc/opt/firefox/firefox "$@"

    This a common idiom for passing on to the next script/program whatever was originally passed to this script.

    BTW, why do you use "env"? Is that necessary, or is that just your general practice?

    FWIW, here are 3 alternatives that come to mind:

    1) (Easiest) Just set MOZ_X11_EGL in your .profile/.login/.bashrc/whatever
    2) Use an alias (tcsh/bash/etc) or function (sh/dash/bash/etc)
    3) If you do do it as a script (as shown above), you might as well exec it:

    MOZ_X11_EGL=1 exec /home/oc/opt/firefox/firefox "$@"

    --
    Christianity is not a religion.

    - Rick C Hodgin -

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Ottavio Caruso@21:1/5 to All on Mon Apr 3 15:36:44 2023
    Hi,

    I'm trying to narrow this down to either my script or Firefox itself.

    I have a rudimentary shell launcher:

    $ cat opt/bin/ff-accel
    #!/bin/sh
    env MOZ_X11_EGL=1 /home/oc/opt/firefox/firefox

    (This is necessary to have Firefox understand video acceleration)

    The script is executable:

    $ ls -l opt/bin/ff-accel
    -rwxr-xr-x 1 oc oc 67 Apr 3 10:52 opt/bin/ff-accel

    If I launch Firefox normally:

    $ /home/oc/opt/firefox/firefox www.google.com

    I get the Google homepage as expected.

    If I launch it this way:

    $ opt/bin/ff-accel www.google.com

    I just get a new instance of FF with a blank page.

    I must have missed a simple thing but I have no idea which one.

    Thanks.


    --
    Ottavio Caruso

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Tom Furie@21:1/5 to Ottavio Caruso on Mon Apr 3 15:42:51 2023
    On 2023-04-03, Ottavio Caruso <[email protected]> wrote:
    I have a rudimentary shell launcher:

    $ cat opt/bin/ff-accel
    #!/bin/sh
    env MOZ_X11_EGL=1 /home/oc/opt/firefox/firefox

    If I launch Firefox normally:

    $ /home/oc/opt/firefox/firefox www.google.com

    I get the Google homepage as expected.

    If I launch it this way:

    $ opt/bin/ff-accel www.google.com

    I just get a new instance of FF with a blank page.

    You're ignoring any arguments you pass to your script.

    Cheers,
    Tom

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Ottavio Caruso@21:1/5 to All on Tue Apr 4 08:43:36 2023
    Am 03/04/2023 um 15:42 schrieb Tom Furie:
    On 2023-04-03, Ottavio Caruso <[email protected]> wrote:
    I have a rudimentary shell launcher:

    $ cat opt/bin/ff-accel
    #!/bin/sh
    env MOZ_X11_EGL=1 /home/oc/opt/firefox/firefox

    If I launch Firefox normally:

    $ /home/oc/opt/firefox/firefox www.google.com

    I get the Google homepage as expected.

    If I launch it this way:

    $ opt/bin/ff-accel www.google.com

    I just get a new instance of FF with a blank page.

    You're ignoring any arguments you pass to your script.

    Cheers,
    Tom

    I know. I just realised that yesterday on my way home.

    --
    Ottavio Caruso

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Ottavio Caruso@21:1/5 to All on Tue Apr 4 08:47:34 2023
    Am 03/04/2023 um 16:05 schrieb Kenny McCormack:
    In article <u0erqc$30uas$[email protected]>,
    Ottavio Caruso <[email protected]> wrote:
    Hi,

    I'm trying to narrow this down to either my script or Firefox itself.

    I have a rudimentary shell launcher:

    $ cat opt/bin/ff-accel
    #!/bin/sh
    env MOZ_X11_EGL=1 /home/oc/opt/firefox/firefox

    This needs to be:

    env MOZ_X11_EGL=1 /home/oc/opt/firefox/firefox "$@"

    Thanks. I just realised that yesterday night on my way home. But are the
    quotes around $@ necessary?


    BTW, why do you use "env"? Is that necessary, or is that just your general practice?

    I copied that from here: https://wiki.debian.org/Firefox#Hardware_Video_Acceleration

    Desktop shortcuts require "env" to work. Do shell scripts not require
    "env" too?


    --
    Ottavio Caruso

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Kenny McCormack@21:1/5 to [email protected] on Tue Apr 4 09:38:52 2023
    In article <u0go77$3c3o9$[email protected]>,
    Ottavio Caruso <[email protected]> wrote:
    Am 03/04/2023 um 16:05 schrieb Kenny McCormack:
    In article <u0erqc$30uas$[email protected]>,
    Ottavio Caruso <[email protected]> wrote:
    Hi,

    I'm trying to narrow this down to either my script or Firefox itself.

    I have a rudimentary shell launcher:

    $ cat opt/bin/ff-accel
    #!/bin/sh
    env MOZ_X11_EGL=1 /home/oc/opt/firefox/firefox

    This needs to be:

    env MOZ_X11_EGL=1 /home/oc/opt/firefox/firefox "$@"

    Thanks. I just realised that yesterday night on my way home. But are the >quotes around $@ necessary?

    Yes, if any of any of the args have spaces in them. "$@" is the usual idiom
    for this. Read more in "man bash" for the differences between $*, $@,
    "$*", and "$@".

    BTW, why do you use "env"? Is that necessary, or is that just your general >> practice?

    I copied that from here: >https://wiki.debian.org/Firefox#Hardware_Video_Acceleration

    Desktop shortcuts require "env" to work. Do shell scripts not require
    "env" too?

    As is the case with such many things, it boils down to whether or not a
    shell is involved. I'm assuming that "desktop shortcuts" don't invoke a
    shell, so you have to use "env" to get some of the shell functionality.
    You don't need it if you already have a shell involved (e.g., in a shell script).

    --
    The randomly chosen signature file that would have appeared here is more than 4 lines long. As such, it violates one or more Usenet RFCs. In order to remain in compliance with said RFCs, the actual sig can be found at the following URL:
    http://user.xmission.com/~gazelle/Sigs/Seriously

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Helmut Waitzmann@21:1/5 to All on Tue Apr 4 21:49:07 2023
    Ottavio Caruso <[email protected]>:
    Am 03/04/2023 um 16:05 schrieb Kenny McCormack:
    In article <u0erqc$30uas$[email protected]>,
    Ottavio Caruso <[email protected]> wrote:

    I'm trying to narrow this down to either my script or Firefox
    itself.

    I have a rudimentary shell launcher:


    $ cat opt/bin/ff-accel
    #!/bin/sh
    env MOZ_X11_EGL=1 /home/oc/opt/firefox/firefox

    This needs to be:

    env MOZ_X11_EGL=1 /home/oc/opt/firefox/firefox "$@"

    Thanks. I just realised that yesterday night on my way home. But
    are the quotes around $@ necessary?

    Yes, they are.  The POSIX standard
    (<http://www.opengroup.org/onlinepubs/9699919799/mindex.html>)
    describes in the volume about the shell command language and the
    utilities (follow the "XCU" link,
    <https://pubs.opengroup.org/onlinepubs/9699919799/utilities/toc.html>)
    what it's going to happen if you don't use the quotes (follow the
    "field splitting" link,
    <https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_06_05>).

    In short:  When not using the quotes, the values of the shell
    parameter (in your use case: each of the positional parameters
    ("$@")) is split into parts at each character which is part of
    the set of characters specified by the "IFS" shell variable. 
    Depending on further conditions these parts are then matched
    against filenames.  This is surely not what you want with your
    script which should pass its positional parameters unmodified to
    firefox.

    Using quotes is the "normal way" of passing values of shell
    parameters into commands.  (That it is the more complicated
    expression than just leaving the quotes away might have its
    origin in the historic development of the shell programming
    language.)

    BTW, why do you use "env"? Is that necessary, or is that just
    your general practice?

    I copied that from here: https://wiki.debian.org/Firefox#Hardware_Video_Acceleration

    Desktop shortcuts require "env" to work. Do shell scripts not
    require "env" too?

    The shell has got a built‐in mechanism of specifying environment
    variables when invoking a simple command (in
    <https://pubs.opengroup.org/onlinepubs/9699919799/utilities/toc.html>
    follow the "simple commands" link
    <https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_09_01>)
    which has got similar capabilities (not exactly the same) like
    the «env» program:  To use it in a shell command line, just put
    the environment assignments in front of the simple command.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Ed Morton@21:1/5 to Ottavio Caruso on Tue Apr 4 17:43:39 2023
    On 4/4/2023 3:47 AM, Ottavio Caruso wrote:
    Am 03/04/2023 um 16:05 schrieb Kenny McCormack:
    In article <u0erqc$30uas$[email protected]>,
    Ottavio Caruso  <[email protected]> wrote:
    Hi,

    I'm trying to narrow this down to either my script or Firefox itself.

    I have a rudimentary shell launcher:

    $ cat opt/bin/ff-accel
    #!/bin/sh
    env MOZ_X11_EGL=1 /home/oc/opt/firefox/firefox

    This needs to be:

         env MOZ_X11_EGL=1 /home/oc/opt/firefox/firefox "$@"

    Thanks. I just realised that yesterday night on my way home. But are the quotes around $@ necessary?

    That's the wrong question. The right question would be "is it necessary
    to remove the quotes?" because quotes in shell aren't something you add
    when you need to, they're something you use by default and only remove
    when you need to. If you think about quotes otherwise you'll end up
    shooting yourself in the foot one day when you think you don't need
    them. Think of quotes like the seatbelt in your car - you shouldn't wait
    til you think you might have an accident to put it on. See https://mywiki.wooledge.org/Quotes for more info.

    Ed.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Janis Papanagnou@21:1/5 to Ed Morton on Wed Apr 5 01:47:22 2023
    On 05.04.2023 00:43, Ed Morton wrote:
    See https://mywiki.wooledge.org/Quotes for more info.

    I wonder why that link lists

    Backticks: `...` is the legacy command substitution syntax;

    under "Quoting"; effectively it's no quoting and has (per se)
    nothing to do with quoting (see also the POSIX reference).

    And why it says

    $"..." : This is a Bash extension.

    (and not "a Ksh extension"); didn't Kornshell introduce that?

    And why

    $'...'

    isn't declared as "extension" at all; isn't that a non-standard
    (also Ksh-?) extension (that's as well borrowed by other shells)?

    But otherwise the link provides some good information.


    As a hint for the OP; if studying large texts behind links is
    cumbersome I suggest to set the argument list to, say,

    set a b "c d" e "f g h" i # here 6 arguments

    and just inspect the output of

    printf "'%s'\n" "$@"
    printf "'%s'\n" "$*"
    printf "'%s'\n" $@
    printf "'%s'\n" $*

    to quickly grasp to what these syntaxes will expand the data;
    observe the number or arguments, its grouping, and preservation
    of spaces.

    Janis

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Jalen Q@21:1/5 to Janis Papanagnou on Wed Apr 5 00:18:52 2023
    On Tuesday, April 4, 2023 at 6:47:27 PM UTC-5, Janis Papanagnou wrote:
    On 05.04.2023 00:43, Ed Morton wrote:
    See https://mywiki.wooledge.org/Quotes for more info.
    I wonder why that link lists

    Backticks: `...` is the legacy command substitution syntax;

    under "Quoting"; effectively it's no quoting and has (per se)
    nothing to do with quoting (see also the POSIX reference).

    And why it says

    $"..." : This is a Bash extension.

    (and not "a Ksh extension"); didn't Kornshell introduce that?

    And why

    $'...'

    isn't declared as "extension" at all; isn't that a non-standard
    (also Ksh-?) extension (that's as well borrowed by other shells)?

    But otherwise the link provides some good information.


    As a hint for the OP; if studying large texts behind links is
    cumbersome I suggest to set the argument list to, say,

    set a b "c d" e "f g h" i # here 6 arguments

    and just inspect the output of

    printf "'%s'\n" "$@"
    printf "'%s'\n" "$*"
    printf "'%s'\n" $@
    printf "'%s'\n" $*

    to quickly grasp to what these syntaxes will expand the data;
    observe the number or arguments, its grouping, and preservation
    of spaces.

    Janis
    ddddvvvddvvd

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)