Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Yes, you can merge two parameter expansions into one command in Bash. For example, you can use the "${parameter:-word}" and "${parameter%word}" expansions together to remove a suffix from a variable and replace it with a different value, all in one command:

filename="example.txt"
new_filename="${filename%.*}.pdf"
echo "Converting ${filename} to ${new_filename}..."

In this example, the first expansion ${filename%.*} removes the suffix ".txt" from the variable filename, and the second expansion ${new_filename:-.pdf} adds the new suffix ".pdf" to the result. The output of the command would be:

Converting example.txt to example.pdf...