2

I have a shell script which uses an array to check dependencies. I'd like to make this into a YASnippet, but YAS recognizes the array value statement ${dependencies[@]} as a placeholder. How can I tell YAS to ignore this placeholder?

# key: write.bash
# name: write.bash
# --
#!/bin/bash

dependencies=("${1:dependency 1}" "${2:dependency 2}")

for i in ${dependencies[@]}; do
if [ "$(which $i)" = "" ] ; then
    echo "EARLY EXIT- $i needs to be installed and on PATH"
    exit 0
    else
    echo "$i installed"
fi;
done 
1
  • I can tab through the placeholder and get the correct syntax using: $${3:{dependencies[@]}} but I would like to avoid the placeholder altogether
    – jeszyman
    Commented Mar 6, 2019 at 18:10

1 Answer 1

3

Use \ to escape $ in ${dependencies[@]}, as noted here. The complete snippet is below:

# key: write.bash
# name: write.bash
# --
#!/bin/bash

dependencies=("${1:dependency 1}" "${2:dependency 2}")

for i in \${dependencies[@]}; do
if [ "$(which $i)" = "" ] ; then
    echo "EARLY EXIT- $i needs to be installed and on PATH"
    exit 0
    else
    echo "$i installed"
fi;
done

Your Answer

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

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