Artificial intelligent assistant

How do I check whether a variable has been passed to a function in Bash? I have this: function abash { if [[ -v $1 ]] then atom ~/Shell/$1.sh else atom ~/.bashrc fi } in my `~/.bashrc` file, so as to make it easier to use Atom to edit my bash scripts, now the problem is that `[[ -v $1 ]]` is meant to be checking whether the input `$1` exists but it does not appear to be, as even when I provide a valid input (e.g., running `abash cd` where `~/Shell/cd.sh` is a file I want to edit) abash opens up `~/.bashrc`. How do I fix this problem? Where did I get the idea for the `[[ -v $1]]` test? This answer.

`bash` conditional expression `-v var` check if _shell variable_ named `var` is set.

When using `[[ -v $1 ]]`, you actually checked whether a variable named by content of `$1` was set. In your example, it means `$cd`, which was never set.

You can simply check if `$1` is non-empty string, using `-n`:


function abash {
if [[ -n "$1" ]]
then
atom ~/Shell/"$1.sh"
else
atom ~/.bashrc
fi
}


* * *

Note that `var` must be a _shell variable_ for `-v var` work. `[[ -v 1 ]]` will never work because `1` is denoted for _positional parameter_.

xcX3v84RxoQ-4GxG32940ukFUIEgYdPy 1d8469e5978a2e55b537f133d40c9054