Results 1 to 7 of 7

Thread: bash testing unset

  1. #1
    Join Date
    Apr 2008
    Location
    Southern California, USA
    Beans
    Hidden!
    Distro
    Ubuntu Development Release

    bash testing unset

    I have no idea if this belongs here or newbe, but:

    I had a rather seemingly bazaar bash test:
    Code:
    if [ -d /etc/X11/xinit/xinitrc.d ] ; then for f in /etc/X11/xinit/xinitrc.d/?*.sh ; do
      [ -x "$f" ] && . "$f"
     done
     unset f
    fi
    exec startlxqt
    Bazaar in that my config-monitor won't work without it. The test I know is weather or not the files are executable. Then does the "unset f" make them un-executable?
    I guess my question is what does "unset f" do. The "f" is relating to the files that are checked, but what gets unset?

    I did google and found this, but not sure of outcome.

  2. #2
    Join Date
    Mar 2010
    Location
    Squidbilly-Land
    Beans
    Hidden!
    Distro
    Ubuntu

    Re: bash testing unset

    if this is bash, then unset removes the variable from having any value and removes it from the variable. It is as if it was never used previously. Basically, it is null. This should work similarly across all Bourne Shell-like shells.

    https://www.tldp.org/LDP/abs/html/internal.html#UNS

    But from the incomplete script above, we don't know if bash is being used at all. That segment appears to just look for files (.sh extensions only) in the specific directory and if those files have execute permissions, run them assuming a Bourne Shell compatible method. Honestly, I wouldn't bother with the unset at all. I don't think it is needed, if there is a loop. On my system, that directory is empty.

  3. #3
    Join Date
    Apr 2012
    Beans
    7,256

    Re: bash testing unset

    The only situation in which I can imagine it making any difference is if you are exporting f, and the variable happens to have some significance in your lxqt environment

  4. #4
    Join Date
    Apr 2008
    Location
    Southern California, USA
    Beans
    Hidden!
    Distro
    Ubuntu Development Release

    Re: bash testing unset

    Thanks for response. The script above is complete in and of itself, but it references two other scripts that for some reason are needed. It all has to do with lxqt-monitor-settings failing to execute. I'll put them here for clairty, but I think it hinges on the the "dbus-update-activation-environment". So if the two files referenced are executable (-x) then something gets unset. I still don't fully understand it.

    "/etc/X11/xinit/xinitrc.d" files:
    Code:
    #!/bin/sh
    systemctl --user import-environment DISPLAY XAUTHORITY
    
    if command -v dbus-update-activation-environment >/dev/null 2>&1; then
            dbus-update-activation-environment DISPLAY XAUTHORITY
    fi
    ===
    #!/bin/sh
    case "${DESKTOP_SESSION-}" in
      gnome*) # Done by gnome-settings-daemon
      ;;
      *)
        # Extra check in case DESKTOP_SESSION is not set correctly
        if [ -z "${GNOME_DESKTOP_SESSION_ID-}" ]; then
          GTK_MODULES="${GTK_MODULES:+$GTK_MODULES:}canberra-gtk-module"
          export GTK_MODULES
        fi
      ;;
    esac
    As I said its partly bash unset understanding, and part "lxqt-monitor-settings" failing , with a ".xinitrc" fix.
    Last edited by VMC; September 5th, 2018 at 02:07 AM.

  5. #5
    Join Date
    Mar 2010
    Location
    Squidbilly-Land
    Beans
    Hidden!
    Distro
    Ubuntu

    Re: bash testing unset

    Code:
    #!/bin/shsystemctl --user import-environment DISPLAY XAUTHORITY
    That line is clearly wrong.
    Code:
    #!/bin/sh
    systemctl --user import-environment DISPLAY XAUTHORITY
    is probably correct. That is **Not** bash. That is Bourne shell and on most Ubuntu systems, it is really "dash."

    The unset f is unimportant. Seriously. Unimportant. You can remove it. The f variable is set just above it and used a few times. THAT is the entire purpose.

    I didn't think that lxqt was going to be released until the fall Lubuntu. I tried to use it with 18.04 back in June and it wouldn't load at all. I chalked it up to being less than alpha ready code. Maybe I'm wrong.

  6. #6
    Join Date
    Apr 2008
    Location
    Southern California, USA
    Beans
    Hidden!
    Distro
    Ubuntu Development Release

    Re: bash testing unset

    TheFu, I made a mistake on the one you pointed out. I edited correctly now. Thanks.

    Also Lubuntu works well as of right now, with some issues relating to using getty auto-login.
    This post is from another LXQT install that I could not understand the "unset" usage. (I still don't).

    So the real change is in the statement:
    Code:
    [ -x "$f" ] && . "$f"
    Am I correct. I'll change it to see.

  7. #7
    Join Date
    Mar 2010
    Location
    Squidbilly-Land
    Beans
    Hidden!
    Distro
    Ubuntu

    Re: bash testing unset

    if whatever is stored in $f exists AND is executable, then run that script (the file stored in $f).

    This is identical:
    Code:
    [ -x "$f" ] && source "$f"
    . (dot) and source mean exactly the same thing in Bourne shell derivatives.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •