[SOLVED] ZSH - PATH problem when using script via udev rule
Linux - SoftwareThis forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
ZSH - PATH problem when using script via udev rule
So, i have migrated to zsh and averything is fine except a little PATH problem. Now, i hava a power saving script that is executed when i unplug the power line (via udev rule). Till migration to zsh averything worked fine but when i changed #!/bin/bash to #!/bin/zsh in script, it doesn't work anymore. I found out that script is workable only if i write full paths in it, eg. /sbin/hdparm... instead of hdparm... When i am in terminal or console PATH variable is working fine. I also found out, for now, that the problem are commands in /sbin and /usr/sbin folder - commands in /usr/bin are working just fine.
# /etc/profile
#Set our umask
umask 022
# Set our default path
PATH="/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin"
export PATH
# Load profiles from /etc/profile.d
if test -d /etc/profile.d/; then
for profile in /etc/profile.d/*.sh; do
test -r "$profile" && . "$profile"
done
unset profile
fi
# Source global bash config
if test "$PS1" && test "$BASH" && test -r /etc/bash.bashrc; then
. /etc/bash.bashrc
fi
# Termcap is outdated, old, and crusty, kill it.
unset TERMCAP
# Man is much better than us at figuring this out
unset MANPATH
My script:
Code:
#!/bin/zsh
case "$1" in
true) # Enable power saving settings on battery
# Device Runtime-PM
#for dpcontrol in /sys/bus/{pci,spi,i2c}/devices/*/power/control; do echo auto > $dpcontrol; done
# Disable nmi_watchdog
echo 0 > /proc/sys/kernel/nmi_watchdog
# kernel write mode
echo 5 > /proc/sys/vm/laptop_mode
echo 1500 > /proc/sys/vm/dirty_writeback_centisecs
# disk powersave
hdparm -S 36 -B 128 /dev/sda &> /dev/null
for i in /sys/class/scsi_host/host*/link_power_management_policy; do echo min_power > $i; done
# sound card powersave
echo 60 > /sys/module/snd_hda_intel/parameters/power_save
echo Y > /sys/module/snd_hda_intel/parameters/power_save_controller
# wlan0 powersave
iwconfig wlan0 power on
# backlight
echo 2 > /sys/class/backlight/acpi_video0/brightness
;;
false) # Return to default on AC power
# Device Runtime-PM
#for dpcontrol in /sys/bus/{pci,spi,i2c}/devices/*/power/control; do echo on > $dpcontrol; done
# Enable nmi_watchdog
echo 1 > /proc/sys/kernel/nmi_watchdog
# kernel write mode
echo 0 > /proc/sys/vm/laptop_mode
echo 500 > /proc/sys/vm/dirty_writeback_centisecs
# disk powersave
hdparm -S 0 -B 254 /dev/sda &> /dev/null
for i in /sys/class/scsi_host/host*/link_power_management_policy; do echo max_performance > $i; done
# sound card powersave
echo 300 > /sys/module/snd_hda_intel/parameters/power_save
echo Y > /sys/module/snd_hda_intel/parameters/power_save_controller
# wlan0 powersave
iwconfig wlan0 power off
#backlight
echo 13 > /sys/class/backlight/acpi_video0/brightness
;;
esac
exit 0
If you intend to keep using zsh, you should spend some time reading The ZSH User's Guide and creating your own .zsh and .zshenv files in your home directory. That alone may solve most of your problems when running scripts written for bash.
Zsh uses the $PATH variable, but is also uses a $path array, which is more flexible than using the PATH env variable.
The Zsh Guide discussion of PATH begins on page 47.
Excerpt:
Quote:
It helps to be able to find external programmes, i.e. anything not part of the shell, any
command other than a builtin, function or alias. The $path array is used for this. Actually,
what the system needs is the environment variable $PATH, which contains a list of directories
in which to search for programmes, separated from each other by a colon. These directories
are the individual components of the array $path. So if $path contains
path=(/bin /usr/bin /usr/local/bin .)
then $PATH will automatically contain the effect of
PATH=/bin:/usr/bin:/usr/local/bin:.
without you having to set that. The idea is simply that, while the system needs $PATH
because it doesn’t understand arrays, it’s much more flexible to be able to use arrays within
the shell and hence pretty much forget about the $PATH form.
It would be better if you created file ~/.zshenv and put your corrections there. By having the corrections in /etc/zsh/zshenv, you risk losing the corrections every time zsh is updated.
You are right but there is one problem. I have a script that is executed by udev and this script is in /etc folder. If i move /etc/zsh/zshenc to ~/.zshenv the udev won't respect this paths in .zshenv.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.