39
7
I would like to know how can I write if conditions inside a bash script on a single line.
For example, how can I write this on a single line, and then put another one just like it on the next?
if [ -f "/usr/bin/wine" ]; then
export WINEARCH=win32
fi
I ask this because I have quite a few aliases in my .bashrc and I have the same .bashrc (synced) on multiple systems, but I don't need all aliases on each systems. I put most of them inside if statements, and it is all working beautifully now but they take a lot of space, 3 lines each plus the blank line between them (i like having them easily visible)
I will also use this technique for environment variables as well.
3You can also write
[ -f "/usr/bin/wine" ] && export WINEARCH=win32
– glenn jackman – 2017-01-20T17:40:00.2903Keep in mind that shorter is not necessarily better. You can get subtle logic errors with the shell's logic operators. Choose what's easier to read and maintain. – glenn jackman – 2017-01-20T21:40:32.447