How to make a perfect bash wrapper script

Issue

I need to make a bash script to replace a certain application.
Script should do some work and then execute said application in a way that everything (parameters both positional and named, env variables, signals etc.) will work as if it was the original application executed.

My idea was to do it like this:

#!/bin/bash

# Do something custom
export PATH=/some/custom/override:$PATH

# Execute the original script
exec php8.1 [email protected]

Is this enough or should I do something else to ensure a perfect substitution?

Solution

You should check your scripts with shellcheck .

Line 7:
exec php8.1 [email protected]
            ^-- SC2068 (error): Double quote array expansions to avoid re-splitting elements.

Use:

exec php8.1 "[email protected]"

Answered By – KamilCuk

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published