eval help

I am trying to expand the variable $user in my alias command and tried
several variations of eval but can't seem to get it to work.

The end result should be either:

oracle_user='sudo su - oracle ' or oracle_user='sudo su - oracle1 '

 
user=$(grep '^oracle:' /etc/passwd | cut -d":" -f1 )
if [ -z "$user" ]
  then
     user=$(grep '^oracle1:' /etc/passwd | cut -d":" -f1 )
     if [ -z "user" ]
     then
         echo "users oracle or oracle1 not found."
      fi
  fi

 
alias -x oracle_user='sudo su - $user '
 
 

Any help would be greatly appreciated

Use double quotes

alias -x oracle_user="sudo su - $user "

And the second test is missing a $ sign.

     if [ -z "$user" ]
alias -x oracle_user='sudo su - $user'
 
alias oracle_user
oracle_user='sudo su - $user'
 

As mentioned above how come $user is not expanded to either oracle or oracle1

The answer is in post #2 .
Variables between single quotes are not expanded. Variables between double quotes are expanded.

thanks i missed the double quotes