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 
  • I can tab through the placeholder and get the correct syntax using: $${3:{dependencies[@]}} but I would like to avoid the placeholder altogether – jeszyman Mar 6 '19 at 18:10
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
| improve this answer | |

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.