KansaiRobot
KansaiRobot

Reputation: 9982

What is % in shell scripts?

Since shell scripting uses one character operators that are very common they are very difficult to google, so I ask here. I have the following line in a shell script:

marvel_dir=${prototxt%marvel*}marvel

where prototxt is the complete path and filename of a prototxt file.

My question is what does "%" do there? How about "*"?

Upvotes: 0

Views: 28

Answers (1)

shamo0
shamo0

Reputation: 101

When the percent sign (%) is used in the pattern ${variable%substring}, it will return content of the variable with the shortest occurrence of substring deleted from the back of the variable.

source here

Upvotes: 3

Related Questions