Arch Linux output redirection with in scripting not working with Pacman -Ss

Hi I am Rupesh from India and I have a system with intel i3 10th gen processor and Asus prime H 510 m-e motherboard. I have installed Arch Linux directly from Arch Linux live image. Everything is working fine except few issues related to bash and other shells.

Previously I have installed Arch Linux using Arch Linux gui installers like

Arch Linux gui

Arch Linux calameries installer alias ALCI

Black arch Linux slim

All of them worked fine but I thought to install Arch Linux using the official live image provided by Arch Linux website.

Yesterday I have installed Arch Linux through booting official live image and using the script arch-install. After installation of kernel and some main packages post processing stopped abruptly. I mean bootloader was not installed as I got error as efibootmgr not found. /etc/fstab was not created.

I have manually installed efibootmgr and after that executed grub-mkconfig and grub-install. I ran genfstab tool to generate fstab file.

At present I am able to login to my Arch Linux system. After that I have installed desktop environments like gnome and plasma.

I am able to boot into my system and login through sddm display manager.

Still I think that something is not configured properly.

I have created a non root user through useradd utility and started working through it instead of root account.

In my non root user account I have opened .bashrc file but unfortunately not found PATH variable and other settings. I am providing the bashrc file so that you can correctly find what's wrong.

I want to install other packages related to mediainfo, variety, x265, x266, aom, ffmpeg etc., which are upto 100.

So I have ran the following commands like

pacman -Ss mediainfo >> search.txt

pacman -Ss ffmpeg >> search.txt

I have found some description about mediainfo ffmpeg and others including package names in search.txt

Finally I have created a text file called input.txt which consists of words related to what I want like mediainfo variety etc.,.

I have created a small bash script which reads all the lines present in input.txt and search for packages related to them.

The script consists of the following line with in while loop

pacman -Ss $name >> search.txt

Here name is the variable which is the line read from input.txt file.

The pacman search command is running properly when I run directly in a terminal emulator like konsole but the same pacman search command is not working in shell script.

For example I want to search for ffmpeg in package database when I issue the command directly in terminal emulator I am able to get correct results.

I have entered the following command in terminal emulator and got the results what I want.

pacman -Ss ffmpeg >> search.txt

I have created a temporary script with name script.sh and placed the above line in it and executed this particular script in terminal emulator but unfortunately search.txt is empty.

I am providing the contents of bashrc and search scripts below.

#
# ~/.bashrc
#

# If not running interactively, don't do anything
[[ $- != *i* ]] && return

alias ls='ls --color=auto'
alias grep='grep --color=auto'
PS1='[\u@\h \W]\$ '
#!/bin/bash

while read name; do
   
   echo $name
   pacman -Ss $name >> search.txt

done < input.txt

What I want to say finally is pacman search command and output redirection are working fine in terminal emulator but not working in script execution.

However I have installed all the packages what I want but I can't understand why pacman search command and output redirection are not working in script execution.

Kindly try to suggest is there anything else to alter for working the system fine and in particular bash and scripting. If you want I am ready to provide any diagnostic information to you.

Regards,
Rupesh.

How do you invoke your script.sh?
Is input.txt in the same working directory, from which the script is executed?
Does it correctly display output of echo $name on your screen when being executed?
Does it display any error messages?

There is always a PATH. It is inherited from the parent process.
In the bash startup files a PATH=... line can be present to override the inherited value.
In any case you can print the value:
echo "$PATH"

Redirecting of pacman output should work as well in a script.
In case pacman reads from stdin (standard input), use another file descriptor. The following also efficiently bundels the stdout to yet another descriptor.

while read name <&3
do
   
   echo "$name"
   pacman -Ss "$name" >&4

done 3< input.txt 4>> search.txt

The 4>> opens+appends the file when the loop starts (and closes when the loop ends), and >&4 writes to the opened stream.

1 Like

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