#!/bin/bash
FILE="$(basename "$1")"
FILE="${FILE/%.jpeg/.jpg}"
Is there anyway to glue these two lines together into a one-liner?
Is there anyway to glue these two lines together into a one-liner? |
|||
|
test:
script contents:
|
|||
|
You can't nest expansions in bash (nor in ksh, ash and other shells apart from zsh). This is only a cosmetic limitation, since as you illustrate you can assign an intermediate expression to a temporary variable. It is a little annoying for one-liners, but in scripts it's arguably better for readability. You could avoid using the external utility
Here, it happens that you can rewrite your script to put the command substitution on the outside. That's not a general phenomenon, nor do you gain anything other than a certain one-liner feeling. Zsh, for better or for worse, does let you nest expansions:
Or you could use zsh's built-in construct instead of
|
|||
|
You could use a single
|
||||
|
Incorporating
(This doesn't exactly answer your question because I can't; not sure if it's possible.) |
|||
|
The Bash |
|||
|
I'd go for :
The second parameter to basename is a suffix to be removed from the file name (see |
|||
|
The line
can be shortened and made more portable with
|
|||
|