This works:
${parameter:-word}
If parameter is unset or null, the expansion of word is substituted. Otherwise, the value of parameter is substituted.
#!/bin/sh if [ -z "$1" ]; then BACKUP_DIR="/home/ubuntu/backups" else BACKUP_DIR="$1" fi echo "${BACKUP_DIR}"
[ -z "$1" ] && BACKUP_DIR="/home/ubuntu/backups" || BACKUP_DIR="$1"
BACKUP_DIR=$([ -z "$1" ] && echo "/home/ubuntu/backups" || echo "$1")
BACKUP_DIR=${1:-"/home/ubuntu/backups"}
${parameter:-word}
If parameter is unset or null, the expansion of word is substituted. Otherwise, the value of parameter is substituted.
No comments:
Post a Comment