DIgou
DIgou

Reputation: 13

Combining part of bash parameters into a string

Alright, so I'm trying to combine some but not all of my script's parameters into one string. I'm trying to write a script that changes spaces in a file name to underscores, and when the option -r is given, it recursively does it to every file in the folder.

Assuming the file is saved as removespaces.sh, if you run removespaces.sh file with spaces.doc it doesn't really have to care about parameters, I can just use $*

but, when I'm trying to do it for an entire folder I now have -r as $1. So I can't just (be lazy) use $*.. how could I create a string that's equal to $2 to end?

Upvotes: 1

Views: 84

Answers (1)

rici
rici

Reputation: 241921

A string of $2 to the end of the parameters:

"${*:2}"

This differs from "${@:2}" in that it concatenates all the arguments, with one space between each. In general, it is possible that neither form is what you want (if, for example, you have files with more than one consecutive space in their name).

Upvotes: 1

Related Questions