Determine if a file is writable by a Bourne script user

Home -> Programming -> Shell script -> Bourne shells

9673 views

From the computer of: Rex (39 recipes)
Created: Oct 20, 2003


0 comments:
View all comments

Add a comment

Add to:
Add to stumbleuponAdd to del.icio.usDigg itAdd to FURL

From a Bourne shell script (sh, ksh, bash, ...), it is possible to test if a file exists and is writable by the user running the script.

if [ -w testfile ]
then
  echo testfile is writable!
else
  echo non writable...
fi

Subscribe to the Tech-Recipes Newsletter

You can get tips like this delivered in your email every week!

Enter your Email

We will never, ever sell your email address or spam you.





Related recipes:

  Determine if a file is readable by current Bourne shell script user
  Determine if file exists in a Bourne/bash shell script
  Bourne/bash shell script functions
  Bourne/bash shell scripts: case statement
  Bourne/bash shell script for loop syntax
  Bourne/bash shell scripts: string comparison
  Bourne/bash shell script: while loop syntax
  Hide password entry in Bourne/bash shell script
  A simple script that waits for a process to complete and then executes a command
  Simple Menu for User Input

 

Sponsored links

 

Login

Nickname

Password

Don't have an account yet? You can create one. As a registered user you have some advantages like theme manager, comments configuration and post comments with your name.