LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 08-19-2021, 08:33 AM   #1
PowaBanga
LQ Newbie
 
Registered: Aug 2021
Posts: 1

Rep: Reputation: Disabled
Bash script to check if file with number version exist


Hi everybody,
I am on Archlinux, with a custom repository, and i am trying to do a little script to check if the package existing in the repository path.

So my problem in my while, is find the good regex to put in my condition to make it work with all packages


Code:
for i in $(pacman -Slq customrepo)
	do
		if [ -f /customrepo/$i-[0-9A-Za-z]*.pkg.tar.* ]
			then
				echo "$i exist"
			else
				echo "$i Don't !"
		fi
done
For exemple, after launch my complete script with bash -x, for "insync" i have this error message :

Code:
+ '[' -f /repository/insync-3.5.1.50115-1-x86_64.pkg.tar.zst /repository/insync-nemo-3.4.0.40973-1-any.pkg.tar.zst ']'
/home/powabanga/Documents/trucs/pkbuilds/kawacheck: line 3: [: /repository/insync-3.5.1.50115-1-x86_64.pkg.tar.zst: binary operator expected
Does anybody can help me to find what should i writte to not have any errors ?

I post here some usefull info if anybody want to help me.

Code:
pacman -Slq customrepo
aic94xx-firmware
antimicrox
arc-icon-theme-git
aurutils
b00merang-ios-13-gtk-theme
b00merang-windows-10-dark-gtk-theme
b00merang-windows-10-dark-icons-theme
b00merang-windows-10-gtk-theme
b00merang-windows-10-icons-theme
b00merang-windows-7-gtk-theme
b00merang-windows-7-icons-theme
b00merang-windows-xp-gtk-theme
b00merang-windows-xp-icons-theme
bindfs
brother-mfc-j5330dw
brscan4
buuf-nestort-icons-theme
cinnamon-sound-effects
cnijfilter-mp250
debtap
dhewm3
dxvk-bin
epsxe
epsxe-plugin-gpu-mesagl
epsxe-plugin-gpu-soft
epsxe-plugin-padjoy
epsxe-plugin-spu-alsa
esound
exe-thumbnailer
ffmpeg3.4
gconf
geforcenow-nativefier
glib
gnome-dds-thumbnailer
gnome-directory-thumbnailer
gnome-source-thumbnailer-git
gnome-web-shortcuts-extension-git
gnome-xcf-thumbnailer
google-chrome
gosync-git
gtupdater
hexchat-python2
hid-nintendo-dkms
hid-nintendo-nso-dkms
httpfs2-2gbplus
humanity-icon-theme
iat
insync
insync-nemo
jmtpfs
jstest-gtk-git
kawa-BM
kawa-Banga
kawa-intel
kawa-nvidia
kawa-nvidia-lts
kawa-papaetmaman
kawa-wine
kawaOS
lib32-aom
lib32-babl
lib32-blas
lib32-cblas
lib32-dav1d
lib32-exiv2
lib32-ffmpeg
lib32-gegl
lib32-gimp
lib32-gsm
lib32-imath
lib32-jasper
lib32-l-smash
lib32-lame
lib32-lapack
lib32-lapacke
lib32-lensfun
lib32-libass
lib32-libbluray
lib32-libdav1d
lib32-libde265
lib32-libexif
lib32-libffmpeg
lib32-libgexiv2
lib32-libheif
lib32-libmng
lib32-libmypaint
lib32-libraw
lib32-libspiro
lib32-libusb-compat
lib32-libvmaf
lib32-libwmf
lib32-libxpm
lib32-luajit
lib32-metis
lib32-mpfr
lib32-numactl
lib32-opencore-amr
lib32-openexr
lib32-openjpeg2
lib32-poppler
lib32-poppler-glib
lib32-srt
lib32-suitesparse
lib32-tbb
lib32-vmaf
lib32-x264
lib32-x265
lib32-xvidcore
libbfio-git
liblightdm-qt5-guest
liblnk-tools-git
libreoffice-extension-grammalecte-fr
libvncserver-git
lightdm-guest
lightdm-guest-account
lightdm-webkit2-theme-material2
megasync-nopdfium
mint-sounds
mint-themes
mint-x-icons
mint-y-icons
mkinitcpio-archiso-git
msitools
nodejs-nativefier
optimus-manager
optimus-manager-qt
pangox-compat
powershell
proftpd
python-liblnk-git
python-sentry_sdk
python-spotipy
python2-bcrypt
qt5-styleplugins
rclone-browser
rclonesync-git
realvnc-vnc-server
rtl8821ce-dkms-git
scangearmp-mp250series
scangearmp-mp270series
scangearmp-mp490series
scangearmp-mp550series
scangearmp-mp560series
scangearmp-mp640series
scangearmp-mpseries-common
screenrotator-git
sdx
skypeforlinux-stable-bin
spotify
spotify-adkiller-git
spotify_dl
srain
sublime-text-4
syncthing-gtk
tango-icon-theme
tclkit
teams
teamviewer
ttf-ms-fonts
ttf-vista-fonts
tuxtype
ubuntu-themes
ufraw-thumbnailer
upd72020x-fw
vgrive
wd719x-firmware
x11vnc-git
xampp
xboxdrv
yaru-gnome-shell-theme
yaru-gtk-theme
yaru-gtksourceview-theme
yaru-icon-theme
yaru-metacity-theme
yaru-session
yaru-sound-theme
yaru-unity-theme
yay
zoom
Code:
ls /customrepo
aic94xx-firmware-30-9-any.pkg.tar.zst                            lib32-libvmaf-1.5.3-1-x86_64.pkg.tar.zst
antimicrox-3.1.6-1-x86_64.pkg.tar.zst                            lib32-libwmf-0.2.12-2-x86_64.pkg.tar.zst
arc-icon-theme-git-20161122-1-any.pkg.tar.zst                    lib32-libxpm-3.5.13-2-x86_64.pkg.tar.zst
aurutils-3.1.2-2-any.pkg.tar.zst                                 lib32-l-smash-2.14.5-1-x86_64.pkg.tar.zst
b00merang-ios-13-gtk-theme-2.0-2-any.pkg.tar.zst                 lib32-luajit-2.0.5-1-x86_64.pkg.tar.zst
b00merang-windows-10-dark-gtk-theme-3.2-1-any.pkg.tar.zst        lib32-metis-5.1.0.p3-1-x86_64.pkg.tar.zst
b00merang-windows-10-dark-icons-theme-1.0-2-any.pkg.tar.zst      lib32-mpfr-4.1.0.p13-1-x86_64.pkg.tar.zst
b00merang-windows-10-gtk-theme-3.2-2-any.pkg.tar.zst             lib32-numactl-2.0.14-1-x86_64.pkg.tar.zst
b00merang-windows-10-icons-theme-1.0-2-any.pkg.tar.zst           lib32-opencore-amr-0.1.5-3-x86_64.pkg.tar.zst
b00merang-windows-7-gtk-theme-3.2-1-any.pkg.tar.zst              lib32-openexr-3.0.5-1-x86_64.pkg.tar.zst
b00merang-windows-7-icons-theme-1.0-1-any.pkg.tar.zst            lib32-openjpeg2-2.4.0-1-x86_64.pkg.tar.zst
b00merang-windows-xp-gtk-theme-3.1-1-any.pkg.tar.zst             lib32-poppler-21.08.0-1-x86_64.pkg.tar.zst
b00merang-windows-xp-icons-theme-1.0-1-any.pkg.tar.zst           lib32-poppler-glib-21.08.0-1-x86_64.pkg.tar.zst
bindfs-1.14.7-1-x86_64.pkg.tar.zst                               lib32-srt-1.4.3-1-x86_64.pkg.tar.zst
brother-mfc-j5330dw-1.0.1-4-x86_64.pkg.tar.zst                   lib32-suitesparse-5.10.0-1-x86_64.pkg.tar.zst
brscan4-0.4.10_1-5-x86_64.pkg.tar.zst                            lib32-tbb-2020.3-2-x86_64.pkg.tar.zst
buuf-nestort-icons-theme-2.0-1-any.pkg.tar.zst                   lib32-vmaf-1.5.3-1-x86_64.pkg.tar.zst
cinnamon-sound-effects-5.7-1-any.pkg.tar.zst                     lib32-x264-3:0.161.r3039.544c61f-2-x86_64.pkg.tar.zst
cnijfilter-mp250-3.40.1-5.1-x86_64.pkg.tar.zst                   lib32-x265-3.5-1-x86_64.pkg.tar.zst
debtap-3.4.2-1-any.pkg.tar.zst                                   lib32-xvidcore-1.3.7-2-x86_64.pkg.tar.zst
dhewm3-1.5.1-1-x86_64.pkg.tar.zst                                libbfio-git-20210815.3bb082c-1-any.pkg.tar.zst
dxvk-bin-1.9.1-1-x86_64.pkg.tar.zst                              liblightdm-qt5-guest-1:1.30.0-3-x86_64.pkg.tar.zst
epsxe-2.0.5-27-x86_64.pkg.tar.zst                                liblnk-tools-git-20210417.r0.g0c9a2c8-1-x86_64.pkg.tar.zst
epsxe-plugin-gpu-mesagl-1.78-5-x86_64.pkg.tar.zst                libreoffice-extension-grammalecte-fr-2.1.2-1-any.pkg.tar.zst
epsxe-plugin-gpu-soft-1.18-2-x86_64.pkg.tar.zst                  libvncserver-git-0.9.13.r30.g0ac531ed-1-x86_64.pkg.tar.zst
epsxe-plugin-padjoy-0.82-4-x86_64.pkg.tar.zst                    lightdm-guest-1:1.30.0-3-x86_64.pkg.tar.zst
epsxe-plugin-spu-alsa-1.9-6-x86_64.pkg.tar.zst                   lightdm-guest-account-1.30.0-4-any.pkg.tar.zst
esound-0.2.41-4-x86_64.pkg.tar.zst                               lightdm-webkit2-theme-material2-0.0.5-1-any.pkg.tar.zst
exe-thumbnailer-0.10.1-1-any.pkg.tar.zst                         megasync-nopdfium-4.5.3.0-1-x86_64.pkg.tar.zst
ffmpeg3.4-3.4.8-3-x86_64.pkg.tar.zst                             mint-sounds-2.1.8.2-1-any.pkg.tar.zst
gconf-3.2.6+11+g07808097-10-x86_64.pkg.tar.zst                   mint-themes-1.8.8-1-any.pkg.tar.zst
geforcenow-nativefier-20201122-1-x86_64.pkg.tar.zst              mint-x-icons-1.6.3-1-any.pkg.tar.zst
glib-1.2.10-18-x86_64.pkg.tar.zst                                mint-y-icons-1.5.8-1-any.pkg.tar.zst
gnome-dds-thumbnailer-2016.02.19-1-any.pkg.tar.zst               mkinitcpio-archiso-git-58.r0.gbdad4a1-1-any.pkg.tar.zst
gnome-directory-thumbnailer-0.1.11-1-x86_64.pkg.tar.zst          msitools-0.101-3-x86_64.pkg.tar.zst
gnome-source-thumbnailer-git-r10.6bacb2d-1-any.pkg.tar.zst       nodejs-nativefier-45.0.0-1-any.pkg.tar.zst
gnome-web-shortcuts-extension-git-r16.2d89c1e-2-any.pkg.tar.zst  optimus-manager-1.4-2-any.pkg.tar.zst
gnome-xcf-thumbnailer-1.0-10-x86_64.pkg.tar.zst                  optimus-manager-qt-1.6.4-1-x86_64.pkg.tar.zst
google-chrome-92.0.4515.159-1-x86_64.pkg.tar.zst                 pangox-compat-0.0.2+2+gedb9e09-3-x86_64.pkg.tar.zst
gosync-git-0.4-1-any.pkg.tar.zst                                 powershell-7.1.3-1-x86_64.pkg.tar.zst
gtupdater-1.1-1-any.pkg.tar.zst                                  proftpd-2:1.3.7b-1-x86_64.pkg.tar.zst
hexchat-python2-2.14.3-1-x86_64.pkg.tar.zst                      python2-bcrypt-3.1.7-4-x86_64.pkg.tar.zst
hid-nintendo-dkms-3.2-2-any.pkg.tar.zst                          python-liblnk-git-20210417.r0.g0c9a2c8-1-x86_64.pkg.tar.zst
hid-nintendo-nso-dkms-1.2-1-x86_64.pkg.tar.zst                   python-sentry_sdk-1.3.1-1-any.pkg.tar.zst
httpfs2-2gbplus-0.1.5-1-x86_64.pkg.tar.zst                       python-spotipy-2.19.0-1-any.pkg.tar.zst
humanity-icon-theme-0.6.15-1-any.pkg.tar.zst                     qt5-styleplugins-5.0.0.20170311-26-x86_64.pkg.tar.zst
iat-0.1.7-4-x86_64.pkg.tar.zst                                   rclone-browser-1.8.0-2-x86_64.pkg.tar.zst
insync-3.5.1.50115-1-x86_64.pkg.tar.zst                          rclonesync-git-3.2.r3.gae6e71d-1-any.pkg.tar.zst
insync-nemo-3.4.0.40973-1-any.pkg.tar.zst                        realvnc-vnc-server-6.7.4-1-x86_64.pkg.tar.zst
jmtpfs-0.5-2-x86_64.pkg.tar.zst                                  rtl8821ce-dkms-git-1.0.5.r128.gf93db73-1-x86_64.pkg.tar.zst
jstest-gtk-git-0.1.0.r115.g420317b-1-x86_64.pkg.tar.zst          scangearmp-mp250series-1.40-11-x86_64.pkg.tar.zst
kawa-Banga-1.1-3-any.pkg.tar.zst                                 scangearmp-mp270series-1.40-11-x86_64.pkg.tar.zst
kawa-BM-0.4-1-any.pkg.tar.zst                                    scangearmp-mp490series-1.40-11-x86_64.pkg.tar.zst
kawa.db                                                          scangearmp-mp550series-1.40-11-x86_64.pkg.tar.zst
kawa.db.tar.gz                                                   scangearmp-mp560series-1.40-11-x86_64.pkg.tar.zst
kawa.files                                                       scangearmp-mp640series-1.40-11-x86_64.pkg.tar.zst
kawa.files.tar.gz                                                scangearmp-mpseries-common-1.40-11-x86_64.pkg.tar.zst
kawa-intel-0.4-5-any.pkg.tar.zst                                 screenrotator-git-1:r25.e1de8b7-1-x86_64.pkg.tar.zst
kawa-nvidia-0.1-1-any.pkg.tar.zst                                sdx-20110317-1-any.pkg.tar.zst
kawa-nvidia-lts-0.1-1-any.pkg.tar.zst                            skypeforlinux-stable-bin-8.75.0.140-1-x86_64.pkg.tar.zst
kawaOS-2-6-any.pkg.tar.zst                                       spotify-1:1.1.56.595-1-x86_64.pkg.tar.zst
kawa-papaetmaman-0.4-1-any.pkg.tar.zst                           spotify-adkiller-git-r177.2dabf81-1-any.pkg.tar.zst
kawa-wine-0.6-1-any.pkg.tar.zst                                  spotify_dl-v7.6.0.r3.g836929c-1-any.pkg.tar.zst
lib32-aom-3.1.1-1-x86_64.pkg.tar.zst                             srain-1:1.2.4-1-x86_64.pkg.tar.zst
lib32-babl-0.1.86-1-x86_64.pkg.tar.zst                           sublime-text-4-4.4113-1-x86_64.pkg.tar.zst
lib32-blas-3.9.0-1-x86_64.pkg.tar.zst                            syncthing-gtk-1:0.9.4.4-2-any.pkg.tar.zst
lib32-cblas-3.9.0-1-x86_64.pkg.tar.zst                           tango-icon-theme-0.8.90-14-any.pkg.tar.zst
lib32-dav1d-0.9.1-1-x86_64.pkg.tar.zst                           tclkit-8.6.11-1-x86_64.pkg.tar.zst
lib32-exiv2-0.27.3-2-x86_64.pkg.tar.zst                          teams-1.4.00.13653-1-x86_64.pkg.tar.zst
lib32-ffmpeg-2:4.4-2-x86_64.pkg.tar.zst                          teamviewer-15.20.6-1-x86_64.pkg.tar.zst
lib32-gegl-0.4.30-2-x86_64.pkg.tar.zst                           ttf-ms-fonts-2.0-12-any.pkg.tar.zst
lib32-gimp-2.10.24-2-x86_64.pkg.tar.zst                          ttf-vista-fonts-1-10-any.pkg.tar.zst
lib32-gsm-1.0.19-1-x86_64.pkg.tar.zst                            tuxtype-1.8.1-1-x86_64.pkg.tar.zst
lib32-imath-3.1.2-1-x86_64.pkg.tar.zst                           ubuntu-themes-20.10-2-any.pkg.tar.zst
lib32-jasper-2.0.33-1-x86_64.pkg.tar.zst                         ufraw-thumbnailer-0.2-2-any.pkg.tar.zst
lib32-lame-3.100-2-x86_64.pkg.tar.zst                            upd72020x-fw-20200826-3-any.pkg.tar.zst
lib32-lapack-3.9.0-1-x86_64.pkg.tar.zst                          vgrive-1.6.1-5-x86_64.pkg.tar.zst
lib32-lapacke-3.9.0-1-x86_64.pkg.tar.zst                         wd719x-firmware-1-7-any.pkg.tar.zst
lib32-lensfun-0.3.95-2-x86_64.pkg.tar.zst                        x11vnc-git-1:0.9.16.r38.gad85c2c-1-x86_64.pkg.tar.zst
lib32-libass-0.14.0-3-x86_64.pkg.tar.zst                         xampp-8.0.9-1-x86_64.pkg.tar.zst
lib32-libbluray-1.3.0-1-x86_64.pkg.tar.zst                       xboxdrv-0.8.8-6-x86_64.pkg.tar.zst
lib32-libdav1d-0.9.1-1-x86_64.pkg.tar.zst                        yaru-gnome-shell-theme-21.10.1-1-any.pkg.tar.zst
lib32-libde265-1.0.8-1-x86_64.pkg.tar.zst                        yaru-gtksourceview-theme-21.10.1-1-any.pkg.tar.zst
lib32-libexif-0.6.22-1-x86_64.pkg.tar.zst                        yaru-gtk-theme-21.10.1-1-any.pkg.tar.zst
lib32-libffmpeg-2:4.4-2-x86_64.pkg.tar.zst                       yaru-icon-theme-21.10.1-1-any.pkg.tar.zst
lib32-libgexiv2-0.12.2-1-x86_64.pkg.tar.zst                      yaru-metacity-theme-21.10.1-1-any.pkg.tar.zst
lib32-libheif-1.12.0-1-x86_64.pkg.tar.zst                        yaru-session-21.10.1-1-any.pkg.tar.zst
lib32-libmng-2.0.3-1-x86_64.pkg.tar.zst                          yaru-sound-theme-21.10.1-1-any.pkg.tar.zst
lib32-libmypaint-1.6.1-1-x86_64.pkg.tar.zst                      yaru-unity-theme-21.10.1-1-any.pkg.tar.zst
lib32-libraw-0.20.2-3-x86_64.pkg.tar.zst                         yay-10.3.1-1-x86_64.pkg.tar.zst
lib32-libspiro-20200505-1-x86_64.pkg.tar.zst                     zoom-5.7.5-1-x86_64.pkg.tar.zst
lib32-libusb-compat-0.1.7-4-x86_64.pkg.tar.zst
Hoping to find some help here

Last edited by PowaBanga; 08-19-2021 at 08:42 AM.
 
Old 08-19-2021, 09:17 AM   #2
TenTenths
Senior Member
 
Registered: Aug 2011
Location: Dublin
Distribution: Centos 5 / 6 / 7
Posts: 3,232

Rep: Reputation: 1407Reputation: 1407Reputation: 1407Reputation: 1407Reputation: 1407Reputation: 1407Reputation: 1407Reputation: 1407Reputation: 1407Reputation: 1407
The * you use twice in the -f /customrepo/$i-[0-9A-Za-z]*.pkg.tar.* test will be expanded to a list of matching file names in the folder, -f expects an individual file name, not multiple file names.
 
Old 08-20-2021, 12:34 AM   #3
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,832

Rep: Reputation: 3089Reputation: 3089Reputation: 3089Reputation: 3089Reputation: 3089Reputation: 3089Reputation: 3089Reputation: 3089Reputation: 3089Reputation: 3089Reputation: 3089
The simplest method would be to place what you have in the 'if' into a for loop and then test the resulting items:
Code:
for i in $(pacman -Slq customrepo)
do
  for f in /customrepo/$i-[0-9A-Za-z]*.pkg.tar.*
  do
	if [ -f "$f" ]
	then
		echo "$i exist"
	else
		echo "$i Don't !"
	fi
  done
done
 
1 members found this post helpful.
Old 08-20-2021, 07:53 AM   #4
michaelk
Moderator
 
Registered: Aug 2002
Posts: 21,814

Rep: Reputation: 4251Reputation: 4251Reputation: 4251Reputation: 4251Reputation: 4251Reputation: 4251Reputation: 4251Reputation: 4251Reputation: 4251Reputation: 4251Reputation: 4251
Or
Code:
for i in $(pacman -Slq customrepo)
do
  if ls /customrepo/$i-[0-9A-Za-z]*.pkg.tar.* >/dev/null 2>&1; then
     echo "$i exists"
  else
     echo "$i Don't !"
  fi
done
 
Old 08-21-2021, 01:35 AM   #5
MadeInGermany
Senior Member
 
Registered: Dec 2011
Location: Simplicity
Posts: 1,805

Rep: Reputation: 814Reputation: 814Reputation: 814Reputation: 814Reputation: 814Reputation: 814Reputation: 814
file_exists function

With a universal function your main code remains lean.
Code:
# at least one arg is a file
file_exists() {
  for _i do [ -f "$_i" ] && return
  done
  return 1
}

for i in $(pacman -Slq customrepo)
do
	if file_exists /customrepo/$i-[0-9A-Za-z]*.pkg.tar.*
	then
		echo "$i exist"
	else
		echo "$i Don't !"
	fi
done
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Selenium: Check whether button exist or not and if exist whether the the text is in it is desired one or not daichiash General 0 07-03-2020 10:17 AM
[SOLVED] Bash script to accept argument and check the exist of directory inside /home using for loop techlifehackblog Linux - Server 6 09-18-2019 01:53 PM
[SOLVED] Bash script to check if file is present or not, check periodically every 30 mins Iyyappan Linux - Server 10 07-03-2013 05:19 AM
Identify and explain the major number, minor number, and revision number in Linux... turbomen Linux - Newbie 1 11-16-2010 02:48 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:52 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration