You are not logged in.

#1 2018-05-22 20:51:19

mntsv
Member
Registered: 2017-01-20
Posts: 24

[Solved] Variable not recognized in command.

[anon@anonpc .scripts]$ pkg="$(sed -n '2p' /home/anon/.scripts/dups)"
[anon@anonpc .scripts]$ echo $pkg
'e2fsprogs'
[anon@anonpc .scripts]$ ls /var/lib/pacman/local/ | grep $pkg
[anon@anonpc .scripts]$ ls /var/lib/pacman/local/ | grep 'e2fsprogs'
e2fsprogs-1.44.0-1
e2fsprogs-1.44.1-1
lib32-e2fsprogs-1.44.0-1
lib32-e2fsprogs-1.44.1-1
[anon@anonpc .scripts]$ ls /var/lib/pacman/local/ | grep 'e2fsprogs'
e2fsprogs-1.44.0-1
e2fsprogs-1.44.1-1
lib32-e2fsprogs-1.44.0-1
lib32-e2fsprogs-1.44.1-1
[anon@anonpc .scripts]$ 

As the code above shows, I define a variable and check to make sure it is defined as what I want. When I try to use the variable, nothing happens; it is as if I grep'd for something that wasn't actually there. However, when I grep for the name directly, everything shows up completely fine. I also copy/pasted the output of my variable (instead of typing the query directly), and it still works out fine.

What am I missing? What am I doing wrong? What is the right way to approach this? I am basically trying to make a simple search and replace for duplicate files.

Last edited by mntsv (2018-05-22 21:59:20)

Offline

#2 2018-05-22 21:19:52

ooo
Member
Registered: 2013-04-10
Posts: 1,638

Re: [Solved] Variable not recognized in command.

I'm no bash expert, but I think you need to export the variable to make it available to sub-processes, in this case grep.
https://stackoverflow.com/questions/115 … out-export

Offline

#3 2018-05-22 21:29:28

N_BaH
Member
Registered: 2015-12-30
Posts: 84

Re: [Solved] Variable not recognized in command.

hi,

the quotes are part of the variable, and thus are not interpreted as quotes.

printf '%s\n' /var/lib/pacman/local/${pkg//\'/}

Last edited by N_BaH (2018-05-22 21:54:54)

Offline

#4 2018-05-22 21:31:46

seth
Member
From: Won't reply 2 private help req
Registered: 2012-09-03
Posts: 78,849

Re: [Solved] Variable not recognized in command.

Also don't grep ls, <lots of swearing here ;-)> use find or globbing.

Offline

#5 2018-05-22 21:59:05

mntsv
Member
Registered: 2017-01-20
Posts: 24

Re: [Solved] Variable not recognized in command.

Thanks N_BaH, that worked.

Offline

#6 2018-05-23 09:49:26

eschwartz
Fellow
Registered: 2014-08-08
Posts: 4,097

Re: [Solved] Variable not recognized in command.

I'm rather confused as to why one would need to find duplicates in pacman's local installation database...

How do you have multiple versions of e2fsprogs installed at the same time???


Managing AUR repos The Right Way -- aurpublish (now a standalone tool)

Offline

Board footer

Powered by FluxBB