0

I need a script in order to, giving a packages list as arguments, the script performs the installation of the packages in one row. For example launching the script in this way:

script package1 package2 package3

it performs the installation in this way:

yum -y install package1 package2 package3

Clearly I'm in a situation in which I can't install them directly but I need to use a script. How could I do? This way install the packages in different rows and is not what I need.

for pkg in "$@"
do
    yum -y install "$pkg"
done
  • yum -y install $* perhaps? But why do it in a script at all? – NickD Jan 25 '18 at 14:14
  • because the script will be execute by another program and the packages list given by the user – intore Jan 25 '18 at 14:27
  • @Kusalananda: How could I do if the list must be given to yum command separated by commas? for example for RHSA: yum -y -v update --advisory=FIRST_RHSA,SECOND_RHSA. Do I have to work with array? Considering that the list is given separated by " " space. – intore Jan 25 '18 at 16:24
2

This seems like a reasonable thing to do in your script:

yum -y install "$@"

"$@" will expand to the individually quoted command line arguments of the script itself, just like it would do in your for-loop. But instead of looping over the arguments, you pass them all to yum -y install in one go.

  • yes it runs and it's very easy. I obtained the same result pushing all the arguments in an array and the executing the installation with the array but your solution is the best. Thanks – intore Jan 25 '18 at 14:32
  • How could I do if the list must be given to yum command separated by commas? for example for RHSA: yum -y -v update --advisory=FIRST_RHSA,SECOND_RHSA. Do I have to work with array? – intore Jan 25 '18 at 15:10

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.