this post was submitted on 07 Oct 2024
11 points (100.0% liked)

Bash

720 readers
1 users here now

Talk about the Bash Shell and Bash scripting

founded 4 years ago
MODERATORS
 

I'm studying bash, and I came across this Stackoverflow thread which contains this bit of code:

var="abcde"
echo ${var%d*}

The output is abc, but I can't figure out why. I understand that %d is used to indicate an integer number and * represents anything, but I can't figure out why those together would truncate var to only 3 characters.

you are viewing a single comment's thread
view the rest of the comments
[–] [email protected] 1 points 5 days ago

You may be confusing that %d with printf syntax. I'm not entirely sure, but I think what the percent sign means is delete everything from the end of string until the first occurence of letter "d"