Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Im writing spec file in which i want to place script to run process from init.d directory. Here it is a part of SPEC file:

%prep   

%{__cat} <<EOF  > myapp.run


prog="IMG APP BACKEND"
exec=%{APP_prefix}/bin/myapp.%{_APP}
config=%{APP_prefix}/etc/myapp%{_APP}.xml                                  

. /etc/rc.d/init.d/functions                                                  

start() {
        if [ $UID -ne 0 || $UID -ne 80 ]; then
                echo "User has insufficient privilege."                       
                exit 4                                                        
        fi
        [ -x $exec ] || exit 5
        [ -f $config ] || exit 6
        echo -n $"Starting $prog: "
        daemon $exec $config && success || failure                            
        retval=$?                                                             
        echo
        [ $retval -eq 0 ] && touch $lockfile                                  
        return $retval                                                        
}

when i open myapp.run i get (same part):

start() {
        if [ 1031 -ne 0 || 1031 -ne 80 ]; then
                echo "User has insufficient privilege." 
                exit 4
        fi
        [ -x  ] || exit 5
        [ -f  ] || exit 6
        echo -n $"Starting : "
        daemon   && success || failure
        retval=0
        echo
        [  -eq 0 ] && touch
        return
}

What im doing wrong ? Why variable UID gets 1031 and so on ?

thx for all answers

share|improve this question

You are using a heredoc with <<EOF. In the 'sh'/bash shells, (as with most other programming languages) variables inside a heredoc are expanded at run time, the same way as within double-quoted strings. For example, $UID is expanded to the user ID of whoever runs the spec file, and $exec is expanded to an empty string because it hasn't been set yet.

$ cat <<EOF
> I am $USER
> EOF
I am grawity

To avoid this, put the limit string in single quotes: <<'EOF'

$ cat <<'EOF'
> I am $USER
> EOF
I am $USER
share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .