LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware
User Name
Password
Slackware This Forum is for the discussion of Slackware Linux.

Notices


Reply
  Search this Thread
Old 09-09-2017, 12:46 PM   #1
orbea
Member
 
Registered: Feb 2015
Distribution: Slackware64-current
Posts: 743

Rep: Reputation: Disabled
Slackware ash bug


When using 'ash-0.4.0-x86_64-2' included in Slackware current to test compatibilty with scripts I discovered the following issue.

Consider this example.

Code:
#!/bin/ash

set -eu

word='test - オウムのジャングル'
test='test - オウムのジャングル keep this'

type="${test#"$word"}"

printf %s\\n "word = $word"
printf %s\\n "test = $test"
printf %s\\n "type = $type"
exit
Expected output should be:

Code:
word = test - オウムのジャングル
test = test - オウムのジャングル keep this
type =  keep this
However with the slackware ash fails to remove $word from $test.
Code:
word = test - オウムのジャングル
test = test - オウムのジャングル keep this
type = test - オウムのジャングル keep this
Now this happens because $word and $test contain the kana 'の', if this character is removed the test script will work correctly with the Slackware ash, but for my purposes I can not assume what letters or characters $word and $test may or may not contain...

The frustrating part is that other ash implementations do not have this problem including the busybox and freebsd ash nor do related shells like dash or yash.

For bonus, consider this more advanced usage which will result in an infinite loop with the Slackware ash...

Code:
#!/bin/ash

set -eu

word='test - オウムのジャングル'
new=

while [ "$word" != '' ]; do
  first="${word%%"${word#?}"}"
  word="${word#"$first"}"
  new="${new}$first"
  printf %s\\n "first = $first"
  printf %s\\n "word = $word"
  printf %s\\n "new = $new"
done

exit
This should save the first letter, remove everything else from the $word variable and then recreate the string in the $new variable. This could be useful if you wanted to replace certain characters without requiring any binaries or any bashisms.
 
Old 09-09-2017, 01:10 PM   #2
Darth Vader
Senior Member
 
Registered: May 2008
Location: Romania
Distribution: DARKSTAR Linux 2008.1
Posts: 1,287

Rep: Reputation: 522Reputation: 522Reputation: 522Reputation: 522Reputation: 522Reputation: 522
I am not sure that the Slackware installer and/or the (generated) initrd are supposed to support Japanese or any Asian languages...

Long story short, I thought that the ASH is a mini-shell, limited like hell.

PS. In fact, it is (still) used (the ASH) in the installer?

Last edited by Darth Vader; 09-09-2017 at 02:01 PM.
 
Old 09-09-2017, 01:21 PM   #3
orbea
Member
 
Registered: Feb 2015
Distribution: Slackware64-current
Posts: 743

Original Poster
Rep: Reputation: Disabled
I am not testing the installer, I use it because I am interested in writing portable scripts that work anywhere. Other ash implementations do not have this problem either...
 
Old 09-09-2017, 01:46 PM   #4
volkerdi
Slackware Maintainer
 
Registered: Dec 2002
Location: Minnesota
Distribution: Slackware! :-)
Posts: 1,262

Rep: Reputation: 3518Reputation: 3518Reputation: 3518Reputation: 3518Reputation: 3518Reputation: 3518Reputation: 3518Reputation: 3518Reputation: 3518Reputation: 3518Reputation: 3518
Yes, the Slackware version of ash is severely limited, and there are no longer any scripts in Slackware (in the installer or elsewhere) that use it. Since it seems that dash is the designated successor to ash on Linux systems, perhaps the solution is to switch to that?
 
5 members found this post helpful.
Old 09-09-2017, 01:55 PM   #5
orbea
Member
 
Registered: Feb 2015
Distribution: Slackware64-current
Posts: 743

Original Poster
Rep: Reputation: Disabled
Dash would work, but another possible idea is to simply change to a different ash implementation which is not quite as limited. The ash in busybox or freebsd seem better maintained for example. I understand the Slackware ash was derived from a netbsd version, but I am not sure what status their current sh is in? Although it may not be your direct concern I wonder how far spread this particular ash is beyond just Slackware?
 
1 members found this post helpful.
Old 09-09-2017, 01:56 PM   #6
Didier Spaier
LQ Addict
 
Registered: Nov 2008
Location: Paris, France
Distribution: Slint64-14.2 on Lenovo Thinkpad W520
Posts: 7,747

Rep: Reputation: 2664Reputation: 2664Reputation: 2664Reputation: 2664Reputation: 2664Reputation: 2664Reputation: 2664Reputation: 2664Reputation: 2664Reputation: 2664Reputation: 2664
I don't think that ash be able to process UTF-8 encoded files.

ash-0.40 shipped in Slackware-current is more that 16 years old... While there has been a proposal for processing UTF-8 in a shell in 1992, I don't think there have been many implementations before 2003.

@Orbea: to test compatibility (assuming that you want that your script be portable, i.e. doesn't need any extension beyond what is specified by POSIX), you could use dash (available from SBo) or just bash in POSIX mode (bash --posix).

@Darth Vader: the Slackware installer uses bash and I don't think it can work as-is with another shell.

PS Sorry, I typed too slow... And anyway all ash implementations are very limited and I don't think any be POSIX compliant. So yes, if it is to be replaced in Slackware dash looks like a good candidate.

Last edited by Didier Spaier; 09-09-2017 at 02:06 PM.
 
1 members found this post helpful.
Old 09-09-2017, 02:09 PM   #7
Darth Vader
Senior Member
 
Registered: May 2008
Location: Romania
Distribution: DARKSTAR Linux 2008.1
Posts: 1,287

Rep: Reputation: 522Reputation: 522Reputation: 522Reputation: 522Reputation: 522Reputation: 522
Didier, thanks for details, my French friend!

@orbea

I think you make a dramatic huge confusion, because looks like today, the shell so called ASH is basically a modular Bash framework: https://github.com/ash-shell/ash

Read: something like a Bash on steroids.

So, looks like the modern ASH is NOT the same with our 16 years old junk...

PS. I wonder, why we do not send in retirement this really old pal, if it is not used anymore?

Last edited by Darth Vader; 09-09-2017 at 02:21 PM.
 
Old 09-09-2017, 02:17 PM   #8
orbea
Member
 
Registered: Feb 2015
Distribution: Slackware64-current
Posts: 743

Original Poster
Rep: Reputation: Disabled
I find the easiest way to test compatibility is to actually try the shells, using dash or bash --posix doesn't teach things like how in ksh 'type' is an alias to 'whence -v' nor will it reveal silent exits in a more limited shell where you left undefined behavior.

Anyways, my main intent was to record this somewhere public and given that this seems to be specific to the ash used by Slackware this seemed to be the best place.
 
1 members found this post helpful.
Old 09-09-2017, 02:21 PM   #9
orbea
Member
 
Registered: Feb 2015
Distribution: Slackware64-current
Posts: 743

Original Poster
Rep: Reputation: Disabled
@Darth Vader: You should realize your link has nothing to do with the Almquist Shell (Ash) despite the misleading name.

https://en.wikipedia.org/wiki/Almquist_shell
https://github.com/ash-shell/ash/issues/41
 
Old 09-09-2017, 02:25 PM   #10
Darth Vader
Senior Member
 
Registered: May 2008
Location: Romania
Distribution: DARKSTAR Linux 2008.1
Posts: 1,287

Rep: Reputation: 522Reputation: 522Reputation: 522Reputation: 522Reputation: 522Reputation: 522
Thanks, I figured out already...

Also, looks like today the old ASH is called for real DASH:

http://gondor.apana.org.au/~herbert/dash/

Latest source being: http://gondor.apana.org.au/~herbert/...h-0.5.9.tar.gz (2016-06-06)

So, I suspect that the other distros use this DASH, eventually symlinked as /bin/ash ...

Last edited by Darth Vader; 09-09-2017 at 02:31 PM.
 
Old 09-11-2017, 01:50 AM   #11
orbea
Member
 
Registered: Feb 2015
Distribution: Slackware64-current
Posts: 743

Original Poster
Rep: Reputation: Disabled
I found a way to work around this issue, but it will still get that one kana wrong... I guess its truly hopeless with this old shell.

To get the first letter.
Code:
#!/bin/ash

set -eu

first='test - オウムのジャングル'

while [ "${#first}" -gt 1 ]; do
  first="${first%?}"
done

printf %s\\n "first = $first"

exit
To recreate the word.
Code:
#!/bin/ash

set -eu

word='test - オウムのジャングル'
new=

printf %s\\n "word = $word"

while [ "$word" != '' ]; do
  first="$word"
  word="${word#?}"
  while [ "${#first}" -gt 1 ]; do
    first="${first%?}"
  done
  new="${new}$first"
done

printf %s\\n "new = $new"

exit
Output:
Code:
word = test - オウムのジャングル
new = test - オウムジャングル
 
Old 09-11-2017, 02:19 AM   #12
Darth Vader
Senior Member
 
Registered: May 2008
Location: Romania
Distribution: DARKSTAR Linux 2008.1
Posts: 1,287

Rep: Reputation: 522Reputation: 522Reputation: 522Reputation: 522Reputation: 522Reputation: 522
@orbea

BUT, the question is: is not BASH present in any honorable distribution?

Make sense for you to insist on mini-shells?

Last edited by Darth Vader; 09-11-2017 at 02:20 AM.
 
Old 09-11-2017, 02:29 AM   #13
orbea
Member
 
Registered: Feb 2015
Distribution: Slackware64-current
Posts: 743

Original Poster
Rep: Reputation: Disabled
Can you please go be rude somewhere else? This thread has nothing to do with bash nor have you left a single useful reply.
 
3 members found this post helpful.
Old 09-11-2017, 02:23 PM   #14
orbea
Member
 
Registered: Feb 2015
Distribution: Slackware64-current
Posts: 743

Original Poster
Rep: Reputation: Disabled
Actually there is a work around, considering that the Slackware ash does not have printf as a builtin and that it falls back to the GNU printf in coreutils which does not have this bug this can be done.

Code:
#!/bin/ash

set -eu

word='test - オウムのジャングル'
test='test - オウムのジャングル keep this'

type="$(printf %s "${test#"$word"}")"

printf %s\\n "word = $word"
printf %s\\n "test = $test"
printf %s\\n "type = $type"
exit
Or:
Code:
#!/bin/ash

set -eu

word='test - オウムのジャングル'
new=

while [ "$word" != '' ]; do
  first="$(printf %s "${word%"${word#?}"}")"
  word="$(printf %s "${word#?}")"
  new="${new}$first"
  printf %s\\n "first = $first"
  printf %s\\n "word = $word"
  printf %s\\n "new = $new"
done

exit
I have also tested bash, dash, ksh, ksh-openbsd, mksh, pdksh, posh, yash and zsh where this continues to work.
 
Old 09-11-2017, 04:16 PM   #15
Richard Cranium
Senior Member
 
Registered: Apr 2009
Location: Carrollton, Texas
Distribution: Slackware64 14.2
Posts: 2,731

Rep: Reputation: 1149Reputation: 1149Reputation: 1149Reputation: 1149Reputation: 1149Reputation: 1149Reputation: 1149Reputation: 1149Reputation: 1149
Quote:
Originally Posted by Darth Vader View Post
@orbea

BUT, the question is: is not BASH present in any honorable distribution?

Make sense for you to insist on mini-shells?
If you exec a shell in a loop, it can make a difference.

The last time someone checked, you can knock a measurable amount of time off of boot startup by using dash in the Slackware init scripts versus bash.
 
1 members found this post helpful.
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
The prompt in ash. stf92 Slackware 4 04-02-2015 02:18 PM
Use bash as an alternative to ash? J_Szucs Linux - General 3 05-30-2005 05:44 AM
ash script (please) sourceman Linux - General 1 04-18-2002 10:38 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware

All times are GMT -5. The time now is 07:38 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration