Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

1 Answer 1

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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.