F
F
for_stupid_answer2015-06-17 17:54:14
linux
for_stupid_answer, 2015-06-17 17:54:14

Checking package installation in FreeBSD via sh?

FreeBSD 10.1
Need to script .sh with conditions.
If the pcre package (as an example) is not installed, then run the command: pkg install pcre
Otherwise, skip.
Which command can be used to check if a package is installed?
Currently checking: pkg info | grep pcre
Is it true? And how are the conditions in .sh files correctly compiled?
UPD:
I would also like to know what command you can find out the user's login, because. if the user is not root, add sudo to the command.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
athacker, 2015-06-17
@for_stupid_answer

Yes, you can check this. Just keep in mind that the combination of characters 'pcre' can be found in a number of packages :-)
How conditions are made -- man test. For syntax examples, you can refer to any of the scripts that are in /etc/rc.d/
User login can be found from environment variables. The setenv command with no options, or printenv is a USER variable.

M
MgmZog, 2015-06-17
@MgmZog

For user login, there is a "whoami" command, for example, which actually answers the question who am I?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question