I can do this as:
if [[ "$is_to_rename" == true ]]
then
printf "path %s\n" "a" >> $logger
else
printf "path %s\n" "a"
fi
But would be nice to reduce the duplicated code printf "path %s\n" "a"
, so tried the following small code:
#!/bin/bash
is_to_rename=true
printf "path %s\\n" "a" if [[ "$is_to_rename" == true ]]; then >> $logger; fi
But throws the error:
./fixer.sh
./fixer.sh: line 66: syntax error near unexpected token `then'
./fixer.sh: line 66: ` printf "path %s\n" "a" if [[ "$is_to_rename" == true ]]; then >> $logger; fi'
It is possible not to keep repeating the code printf "path %s\n" "a"
? [And do it in one line? (just for fun)]