SlackwareThis Forum is for the discussion of Slackware Linux.
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.
Only problem is that once you start making changes like this you're stepping outside of "Official Slackware" and that may make your system maintenance more difficult when Pat ships a new set of init-scripts.
Well, I think that Pat just follows the old saying here "if it ain't broke, don't fix it". If he were to rewrite all the init scripts from scratch, maybe he would use another syntax here and there. But there is no need for that as far as I know (please no more flame war about _you_know_what_).
Last edited by Didier Spaier; 06-07-2014 at 11:44 AM.
Reason: Last sentence deleted, usless and statemrnt not checked.
I giggled when I saw this recently.
From pm-functions (part of pm-utils)
Code:
#!/bin/sh
...
# Simple little logging function.
# We do it this way because 'echo -n' is not posix.
log()
{
is_set "$LOGGING" || return 0;
local fmt='%s\n'
[ "$1" = "-n" ] && { fmt='%s'; shift; }
printf "$fmt" "$*"
}
...
# always fall back to kernel methods if nothing else was declared
if [ -z "$SUSPEND_MODULE" ]; then
if grep -q mem /sys/power/state; then
SUSPEND_MODULE="kernel"
do_suspend() { echo -n "mem" >/sys/power/state; }
elif [ -c /dev/pmu ] && pm-pmu --check; then
SUSPEND_MODULE="kernel"
do_suspend() { pm-pmu --suspend; }
elif grep -q standby /sys/power/state; then
SUSPEND_MODULE="kernel"
do_suspend() { echo -n "standby" >/sys/power/state; }
fi
fi
Just an example of POSIX compliance being inconsistently applied in upstream and how POSIX compliance can result in some ugly code constructions.
BTW There are also bashisms in the code, despite the /bin/sh shebang.
Removing bash is a larger task than just looking at the init scripts.
Well, I think that Pat just follows the old saying here "if it ain't broken, don't fix it". If he were to rewrite all the init scripts from scratch, maybe he would use another syntax here and there. But there is no need for that as far as I know (please no more flame war about _you_know_what_).
Well, what would the point be? bash is a 'required' package in Slackware, meaning that we know some parts of the OS rely upon it.
You'd remove bash at your peril.
I added bashisms into the initrd 'init' script because it meant I could achieve a string manipulation inside of bash rather than forking to some other utilities. In my opinion since you're using a particular language which is mandated to be present, you should exercise its abilities where possible - particularly if it helps improve efficiency.
If these scripts were intended to be used outside of Slackware then it would make sense to make them as POSIX compliant as possible to maximise their usability. But they aren't.
I added bashisms into the initrd 'init' script because it meant I could achieve a string manipulation inside of bash rather than forking to some other utilities.
I guess you mean /etc/rc.d/rc.S in the initrd? I ask because in Slackware initrd as well as in intrd-versatile.img (I just had a look there) /sbin/init links to /bin/busybox.
Any initrd is a special case. In this case, whether you mean the intrd from the installer, or one generated by mkinitrd, bash is not included. rc.S and all other init scripts are not used by the initrd. Any scripts run by the initrd will be busybox/sh compatible -as are doinst.sh scripts.
I guess you mean /etc/rc.d/rc.S in the initrd? I ask because in Slackware initrd as well as in intrd-versatile.img (I just had a look there) /sbin/init links to /bin/busybox.
I was confused where I'd made the change- it was actually mkinitrd. One would have to be careful with the initrd itself since it only has Busybox. The installer uses bash.
About the only place I would expect bashisms to be rare would be those multi-platform packages that are expected on things like AIX and SunOS. Though even there, bash is also frequently installed on the system.
cat /etc/crypttab | grep -v "^#" | grep -v "^$" | while read line; do ... ; done
It removes empty lines and any commented lines then reads each line. Each line that is read gets put into an array and each element of the array is then put into it's own variable.
On a secondary note, that could be replaced with:
Code:
egrep -v '(^#|^$)' /etc/crypttab | while read -r line; do ... ; done
Quote:
as an experiment (and to get rid of bash) i changed /bin/sh to point to /bin/mksh.
I don't know too much about mksh specifically, but ksh itself still comes with arrays (some of them are interchangeable with bash-arrays). So even by pointing the symlink to ksh there might be some things that you missed in this little endeavor.
I see a related thread in the "Similar Threads" section and it asks "anyone uses ash as /bin/sh?" which is probably the closest to a POSIX/bourne shell that Slackware has.
There are some things that aren't part of the bourne shell or defined by POSIX in the almquist shell (local for example), but it's pretty close.
I actually don't mind bash when it's running in bash mode, and some of the bashisms are actually quite useful. It's when it's trying to take on its POSIX persona when run as 'sh' that you start to hit problems, particularly around shell invocation.
BTW, doesn't debian use 'dash' to provide their /bin/sh?
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.