Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Extracting words in quotes in shell script

Tags:

bash

shell

awk

I am making a shell script that will automate the install process of Arch Linux AUR packages. I need to list all dependencies of the package (to check if they are installed), they appear like this in install script:

depends=('sdl' 'libvorbis' 'openal')

The easiest way (or the only idea) that I could come up with is something like this:

grep "depends" PKGBUILD | awk -F"'" '{print $2 "\n" $4 "\n" $6;}'

But the dependency count varies from package to package. So, how I output the names in quotes if the word count is varying?

Thanks in advance,

-skazhy

like image 261
skazhy Avatar asked Jan 29 '26 05:01

skazhy


1 Answers

If the depends is just one line, one thing you may try is to evaluate the line in bash itself... This will lead to an array called "depends" that holds all the values. Seems tricky, but not with dynamic languages:

depend_line=`grep depends $PKGBUILD`
eval "${depend_line}"
echo ${depend[0]} # Will print sdl in your example
like image 149
Diego Sevilla Avatar answered Jan 31 '26 20:01

Diego Sevilla