0

I'm trying to create a install.sh script that checks if all my dependencies are installed and then triggers the dependencies scripts.

#!/bin/bash

phpValidation() {
    if hash php 2>/dev/null; then
        echo 'we have php'
    else
        echo 'no php'
    fi
}

composerValidation() {
    if type -t composer ; then #this part does not work
        echo 'we have composer'
    else
        echo 'no composer?!'
    fi
}

It works fine for php and yarn, but because composer is an alias it does not get trigged through the script.

How can I check if composer is installed and then trigger it?

2
  • I would let the user config the cmd (path) used to trigger composer. Commented Nov 22, 2018 at 7:43
  • Just invoke composer and handle the case that it fails. Commented Nov 25, 2018 at 23:43

1 Answer 1

3

I found a pretty good script here and modified it to fit my needs.

Here is my simplified version I came up with in the end:

//  Check for composer
composer -v > /dev/null 2>&1
COMPOSER=$?
if [[ $COMPOSER -ne 0 ]]; then
    echo 'Composer is not installed'
else
    echo 'Composer is installed'
fi
Sign up to request clarification or add additional context in comments.

1 Comment

and this works because COMPOSER is a environment variable holding what you just put in above ?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.