0

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

0

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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