LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware
User Name
Password
Slackware This Forum is for the discussion of Slackware Linux.

Notices


Reply
  Search this Thread
Old 08-16-2019, 01:30 PM   #1
phalange
Member
 
Registered: May 2018
Distribution: Slackware, FreeBSD, Debian
Posts: 355

Rep: Reputation: 184Reputation: 184
Bash question about slackbuild doinst.sh


Sorry if this is elementary, but I want to clearly understand what this is doing:

Code:
if [ -x /usr/bin/update-desktop-database ]; then
  /usr/bin/update-desktop-database -q usr/share/applications >/dev/null 2>&1
fi

if [ -x /usr/bin/update-mime-database ]; then
  /usr/bin/update-mime-database usr/share/mime >/dev/null 2>&1
fi
I understand that
Code:
/dev/null 2>&1
is saying, "ignore the Standard Error and Standard Out for the two programs respectively", but under what condition? And why? Is "-x" debug?

Thanks.
 
Old 08-16-2019, 01:36 PM   #2
montagdude
Senior Member
 
Registered: Apr 2016
Distribution: Slackware
Posts: 2,011

Rep: Reputation: 1619Reputation: 1619Reputation: 1619Reputation: 1619Reputation: 1619Reputation: 1619Reputation: 1619Reputation: 1619Reputation: 1619Reputation: 1619Reputation: 1619
"if [ -x file ]; then" means that the command inside the if statement will occur if file exists and is executable. The ">/dev/null 2>&1" just means that the output of the command will be sent to nowhere.
 
1 members found this post helpful.
Old 08-16-2019, 01:38 PM   #3
ehartman
Senior Member
 
Registered: Jul 2007
Location: Delft, The Netherlands
Distribution: Slackware
Posts: 1,674

Rep: Reputation: 888Reputation: 888Reputation: 888Reputation: 888Reputation: 888Reputation: 888Reputation: 888
Quote:
Originally Posted by phalange View Post
Sorry if this is elementary, but I want to clearly understand what this is doing:

Is "-x" debug?
See "man test" too: -x means: if file "exist AND is executable", so it tests if the two update programs can be executed and if so it executes them, without showing any output (or errors).
 
1 members found this post helpful.
Old 08-16-2019, 02:44 PM   #4
phalange
Member
 
Registered: May 2018
Distribution: Slackware, FreeBSD, Debian
Posts: 355

Original Poster
Rep: Reputation: 184Reputation: 184
Ok, so -x we test if database program is present and is executable. If yes, we update it. If no, we ignore it. Neither route raises an error or shows output. Is this accurate?

And just for my own clarity, in what scenarios would I NOT use this doinst.sh script? It seems pretty useful across the board.
 
Old 08-16-2019, 04:09 PM   #5
Didier Spaier
LQ Addict
 
Registered: Nov 2008
Location: Paris, France
Distribution: Slint64-15.0
Posts: 11,081

Rep: Reputation: Disabled
Quote:
Originally Posted by phalange View Post
Ok, so -x we test if database program is present and is executable. If yes, we update it. If no, we ignore it. Neither route raises an error or shows output. Is this accurate?
Yes
Quote:
And just for my own clarity, in what scenarios would I NOT use this doinst.sh script? It seems pretty useful across the board.
In no scenario. You won't need these updates if you do never choose an application to start based on a .desktop file's content or a mime type, but even in this case running the doinst.sh is harmless.
 
1 members found this post helpful.
Old 08-16-2019, 04:42 PM   #6
orbea
Senior Member
 
Registered: Feb 2015
Distribution: Slackware64-current
Posts: 1,950

Rep: Reputation: Disabled
I just want to point out that '-x' is not true with only files, it will also be true with directories that are executable (755). It would probably be safer to check both '-f' and '-x' to make sure its an executable file, but in practice it mostly doesn't matter.
 
1 members found this post helpful.
Old 08-16-2019, 09:06 PM   #7
phalange
Member
 
Registered: May 2018
Distribution: Slackware, FreeBSD, Debian
Posts: 355

Original Poster
Rep: Reputation: 184Reputation: 184
Excellent, thanks to all above for the helpful insights.
 
Old 08-17-2019, 04:42 AM   #8
ehartman
Senior Member
 
Registered: Jul 2007
Location: Delft, The Netherlands
Distribution: Slackware
Posts: 1,674

Rep: Reputation: 888Reputation: 888Reputation: 888Reputation: 888Reputation: 888Reputation: 888Reputation: 888
Quote:
Originally Posted by orbea View Post
it will also be true with directories that are executable (755).
All directories are executable (or rather searchable, that's what the "x" means for directory files), so -e (exists) and -x are indistinguable for directories (or should be).
You cannot use ls or such (no wildcards like * or ? either) on directories that are NOT searchable (although you can open files IN it of which you already know the exact filename, that only needs the directory to be readable).
 
Old 08-17-2019, 06:58 AM   #9
orbea
Senior Member
 
Registered: Feb 2015
Distribution: Slackware64-current
Posts: 1,950

Rep: Reputation: Disabled
Quote:
Originally Posted by ehartman View Post
All directories are executable (or rather searchable, that's what the "x" means for directory files), so -e (exists) and -x are indistinguable for directories (or should be).
You cannot use ls or such (no wildcards like * or ? either) on directories that are NOT searchable (although you can open files IN it of which you already know the exact filename, that only needs the directory to be readable).
If you want to navigate a directory it needs to be executable, but there is no reason someone can't change the permissions for a directory with chmod where -e would match, but -x wouldn't. I think its best to use both -f and -x for executable files and -d for directories, but as I already said -x is usually enough for executable files.
 
  


Reply



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
[SOLVED] About creating symlinks in .SlackBuild and doinst.sh cigerma Slackware 7 12-31-2011 06:31 AM
Can I just generate doinst.sh with package? binarybob0001 Slackware 11 11-03-2007 01:07 PM
doinst.sh syntax (help please) Dark Carnival Slackware 3 01-25-2007 09:08 AM
doinst.sh i need to install packages using command line Clarence27 Zenwalk 2 10-07-2006 07:03 AM
appending to perllocal.pod via doinst.sh jong357 Slackware 1 10-31-2005 10:48 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware

All times are GMT -5. The time now is 11:43 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