Ok #asknostr

Is there a way to do a dry run of a shell script to test it? Bouns points if i can do it in vscode.

So far ive been making changes pushing to a private git repo, pulling it on a seprate computer then running the script. Seems like a super slow way to test things.

Reply to this note

Please Login to reply.

Discussion

A lot of the logic in a shell script is about executing other commands. You can mock those commands by either changing PATH, using aliases or defining functions.

I don't know if that is what you meant by "dry run", but that's the only thing I can think of.

I more or less just want to make sure that things are executing in the proper order and that the sections where i have user input are working correctly without necessarily installing a bunch of stuff on my computer.

Ok, let's say I wanna test this script, without installing docker-compose:

$ cat manage.sh

#!/bin/sh

RUNNING_IDS=$(docker-compose ps -q)

if [ -z "$RUNNING_IDS" ]; then

echo "docker-compose is not running."

exit 1

fi

docker-compose exec -e LOG_LEVEL=${LOG_LEVEL:-INFO} backend python3 manage.py "$@"

I can use the PATH trick:

$ printf '#!/bin/sh' > docker-compose && chmod +x docker-compose && PATH=.:$PATH ./manage.sh

docker-compose is not running.

Here I create a docker-compose file (that is just an empty shell script), and called the script that I wanted to test with the current directory added to the PATH.

Sick when im off work ill test this. Thanks. Kinda new to shell scripting and making one that "holds the users hand" has been a fun challenge.