Substring expansion "${string%%' '*}" doesn't work

Bug #1833817 reported by janlz
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
dash (Ubuntu)
New
Undecided
Unassigned

Bug Description

The following substring expansion to get the first word of a string separated by spaces doesn't work using dash 0.5.8-2.10 on Ubuntu 18.04 LTS:

string="one two three four"
first="${string%%' '*}"
printf "%s\n" "$first"

It prints "one two three four", instead of "one". This works on bash and Solaris sh, but not in dash.

Oddly, not putting the white space between single quotes works:
string="one two three four"
first="${string%% *}"
printf "%s\n" "$first" # Prints "one"

Tags: bionic
janlz (janlz)
tags: added: bionic
summary: - Parameter expansion "${string%%' '*}" doesn't work
+ Substring expansion "${string%%' '*}" doesn't work
description: updated
janlz (janlz)
description: updated
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.