Install apps from a simple list from another directory

Instead of putting the list of apps inside the script itself I would like to get the list from another directory. (I read that I can use dirname to do this but I don’t know how). How can I install something using a simple list from the data/fav.list for example? That way I could edit fav.list at any time without messing with the install script. Thank you very much.

#!/bin/bash	

PACMAN_INSTALL=(
	curl
	yay
	lsd
	bat
	duf
	fd
)

for app_to_install in ${PACMAN_INSTALL[@]}; do
  if ! pacman -Q | grep -q $app_to_install; then
    pacman -S "$app_to_install" --noconfirm
  else
    echo -e "\e[32;1m[DONE]\e[0m - $app_to_install"
  fi
done
#!/usr/bin/env bash

YOUR_FILE="$(dirname "${BASH_SOURCE[0]}")/fav.list"

readarray -t PACMAN_INSTALL < "${YOUR_FILE}"
declare PACMAN_INSTALL

for app_to_install in "${PACMAN_INSTALL[@]}";
do
    if ! pacman -Qq | grep -q "^${app_to_install}$";
    then
        pacman -S "${app_to_install}" --noconfirm
    else
        echo -e "\e[32;1m[DONE]\e[0m - ${app_to_install}"
    fi
done

This way, your THE_FILE variable holds the path from the same directory as the script.

1 Like

provide the filename to the script e.g.

scriptname ~/fav.list
#!/bin/bash

sudo pacman -Syu - < "$1" --noconfirm --needed
1 Like

as @linux-aarhus and you can add --needed for replace your bad grep !

pacman -Q | grep -q $app_to_install;

for bat grep found “libatasmart…libatomic_ops” :wink:

best is

pacman -Qq | grep -E ^bat$
1 Like

transfuse has this option too

2 Likes

Thank you so much! It worked.

I don’t know if I’m doing this correctly commenting on a topic already resolved, I’m still learning the rules, but I wouldn’t like to open another topic.

This works when the list is in the same script directory. What if the list was in another directory? e.g.!

IMG_20211122_084956|690x265

Just feed the complete file path to the script

scriptname /data/saved/configs/fav.list

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.