LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 05-10-2017, 05:52 AM   #1
orri23
LQ Newbie
 
Registered: May 2017
Posts: 3

Rep: Reputation: Disabled
[[ ! -w ${file} ]] - What is the "!" doing and what is the "-w" doing?


if [[ ! -w ${file} ]] ; then
echo "You do not have write permission."

What is this doing? I don't seem to find much or anything at all about "-w", and little about "!". Thank you if someone helps.
 
Old 05-10-2017, 06:04 AM   #2
hydrurga
LQ Guru
 
Registered: Nov 2008
Location: Pictland
Distribution: Linux Mint 21 MATE
Posts: 8,048
Blog Entries: 5

Rep: Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925
File test operators: http://tldp.org/LDP/abs/html/fto.html

! is the negation operator

It's worth your while working through the Advanced Bash-scripting Guide:

http://tldp.org/LDP/abs/html/part1.html

For a gentler introduction:

https://www.howtoforge.com/tutorial/...pting-lessons/
 
1 members found this post helpful.
Old 05-10-2017, 06:12 AM   #3
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,840

Rep: Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308
you may also try: man test (although it is not the same, but quite similar), and man bash (look for conditional expressions)
 
Old 05-10-2017, 09:04 AM   #4
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware (15 current), Slack15, Ubuntu studio, MX Linux, FreeBSD 13.1, WIn10
Posts: 10,342

Rep: Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242
7.3. Other Comparison Operators

some more to look at ..

the use of the ! (not) in that example is correct logic. If you are checking for something that is 'not' to be true. In other words, if the value you're looking for is not there then it returns 'true' then act upon it accordingly.


Code:
if [[ ! -w ${file} ]] ; then
if it is not working then:
The question then is the code to get the value into your variable named 'file'. if the value within the variable is there and correct, then it is your logic that is now backwards.

Logical Not !

Last edited by BW-userx; 05-10-2017 at 09:27 AM.
 
Old 05-10-2017, 08:38 PM   #5
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,359

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
Actually "if $file is not writable (for user running the test) then ..."
See link provided by hydrurga
 
  


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] X: "loading extension glx" "no screens found" "fatal server error" (w/ nvidia driver) Geremia Slackware 7 12-29-2014 11:00 AM
[SOLVED] "net rpc" "failed to connect to ipc$ share on" or "unable to find a suitable server" larieu Linux - General 0 11-09-2014 12:45 AM
how can I "cat" or "grep" a file to ignore lines starting with "#" ??? callagga Linux - Newbie 7 08-16-2013 06:58 AM
unpredictable "delete" "move to trash" or "cut" file menu option dorianrenato Linux - General 3 11-28-2011 06:41 PM
LXer: Displaying "MyComputer", "Trash", "Network Servers" Icons On A GNOME Desktop LXer Syndicated Linux News 0 04-02-2007 08:31 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

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