A little bash function, assigning attributes
What you're doing is perfectly fine.

If you absolutely want to shorten it (at a slight loss of readability) for whatever reason you could do it this way (at least in bash):

fn() {
    [ -z "$1" ] &amp;&amp; read -p "username:" username || username=$1
    echo "username is $username"
}


Output (in a bash environment):

$ fn() {
&gt;     [ -z "$1" ] &amp;&amp; read -p "username:" username || username=$1
&gt;     echo "username is $username"
&gt; }
$ fn
username:xx
username is xx
$ fn yy
username is yy
$