Sponsored Content
Top Forums Shell Programming and Scripting Test if a script can cd into a directory Post 302836819 by dexdex200 on Wednesday 24th of July 2013 05:57:28 PM
Old 07-24-2013
Test if a script can cd into a directory

Is there a way for a bash script to test if it can cd into a directory without actually attempting to cd into it?

I am looking for something along the lines of:

Code:
if [ -d $dir ];then
     #code to execute
fi

except in this case I don't want to test if the directory exists; what I want is to test if the script has the permission to cd into the directory.
I know there are other ways of achieving this but does bash provide a shortcut? Smilie
 

10 More Discussions You Might Find Interesting

1. HP-UX

How to test directory availibility

Hello, I'm trying to test if a directory specified in a script parameter is available or not. I wrote a little code to do so, but there's a problem because I receive an error message. My code: #Verify command parameter if then echo 'Incorrect command parameter' echo... (3 Replies)
Discussion started by: santuna
3 Replies

2. Shell Programming and Scripting

how to test filename is file or directory

hi all plz let me how to test output of "tail -1 filelist.lst" is file or directory. regards -Bali Reddy (1 Reply)
Discussion started by: balireddy_77
1 Replies

3. UNIX for Advanced & Expert Users

test if there are files in directory

Hi, I am trying to test if there are files in a directory and if theres i want to get a list. Any ideas? Thanks in advance (1 Reply)
Discussion started by: RSAM2007
1 Replies

4. Shell Programming and Scripting

test for directory being subdir of another directory

I've been using the following code to make sure a shell script only runs under a "safe" directory. Comments/Improvements? #!/bin/sh #----------------------------------------------------------------------------# #..........................................................#... (8 Replies)
Discussion started by: hackware
8 Replies

5. Solaris

test and .test in same directory

i am using solaris 5.10. i can create two different files "test" and ".test" in the same directory. now suppose i want to change the attribute of the hidden file .test to visible is it possible??? since "." is just an attribute to mark a file hidden why is unix allows creation of "file" and... (14 Replies)
Discussion started by: vikashtulsiyan
14 Replies

6. Shell Programming and Scripting

Problem when test to see if directory exists

Hi, I'm writing a shell script that will create a folder if it does not exist yet. Here's the script: (this if statement is inside a while loop) folderName="Pics" if ! test -d folderName then mkdir $folderName fi However, after the folder Pics has been created, every time the... (3 Replies)
Discussion started by: trivektor
3 Replies

7. UNIX for Dummies Questions & Answers

rm: Unable to remove directory /mnt/users/test/logs/: File exists

rm: Unable to remove directory /mnt/users/test/logs/: File exists ls -latr total 191208 drwxrwxrwx 6 test echo 4096 Jul 3 22:36 .. -rwxrwxrwx 1 test echo 97692804 Jul 3 22:36 .nfsDFA4 drwxrwxr-x 2 test echo 4096 Jul 3 23:00 . M not able to delete... (4 Replies)
Discussion started by: solitare123
4 Replies

8. Shell Programming and Scripting

FIle (directory) test operator (bash)

I'm almost pulling out my hair trying to figure out what's wrong with this... there's no reason I can see that it shouldn't be working. It seems that the code acts as though the conditional statement is true no matter what - I've even tried removing the negation operator, but it always goes into... (5 Replies)
Discussion started by: wildbluefaerie
5 Replies

9. Shell Programming and Scripting

Test on string containing spacewhile test 1 -eq 1 do read a $a if test $a = quitC then break fi d

This is the code: while test 1 -eq 1 do read a $a if test $a = stop then break fi done I read a command on every loop an execute it. I check if the string equals the word stop to end the loop,but it say that I gave too many arguments to test. For example echo hello. Now the... (1 Reply)
Discussion started by: Max89
1 Replies

10. Shell Programming and Scripting

How to check weather a string is like test* or test* ot *test* in if condition

How to check weather a string is like test* or test* ot *test* in if condition (5 Replies)
Discussion started by: johnjerome
5 Replies
Test::Assertions::TestScript(3pm)			User Contributed Perl Documentation			 Test::Assertions::TestScript(3pm)

NAME
Test::Assertions::TestScript - Base for test scripts SYNOPSIS
use Test::Assertions::TestScript; use Module::To::Test qw( frobnicate ); ASSERT(frobnicate(),"Frobnicate returns true"); DESCRIPTION
Test::Assertions::TestScript provides a base for writing test scripts. It performs some common actions such as setting up the @INC path and parsing command-line options, specifically: o The lib and t/lib directories are added to @INC. o The current directory is changed to the directory the script is in. o Test script command-line options are parsed. (See "COMMAND-LINE OPTIONS") o The test set of functions from Test::Assertions are imported into your test script. Test::Assertions::TestScript makes certain assumptions about the filesystem layout of your project: o Modules that you are testing are in the lib directory of your project. o Test scripts are in the t directory. o There may also be a t/lib directory for any modules written for the test process. Test::Assertions::TestScript should be "use"d before any modules that you intend to test. OPTIONS
Options can be supplied to the import function. These should be placed after the "use" or "import". For example use Test::Assertions::TestScript( tests => 10, options => { 'b', $opt_b }) The following options are defined: tests The number of tests to pass to "plan tests" from Test::Assertions. For example to tell Test::Assertions::TestScript that the script contains 42 tests: use Test::Assertions::TestScript tests => 42; options A hashref of additional options to capture via Getopt::Long. The "options" import parameter is passed verbatim to GetOptions, so something along the following lines is required in order to capture the "-b" command line option: use Test::Assertions::TestScript( options => { 'b' => $opt_b } ); COMMAND-LINE OPTIONS A script based on Test::Assertions::TestScript will detect the following command line options. -t Shallow tracing. Traces are "print"ed and AutoImport is turned on. -T Deep tracing. Traces are "print"ed and AutoImport is turned on. --trace-module=MODULE Imports tracing into MODULE specifically. Can be specified multiple times. -s Save generated output. You will need to write the actual code to do this in your testscript, but you can inspect $Test::Assertions::TestScript::SAVE_OUTPUT to see whether this argument was given. Be aware that all other command line options will be disregarded unless the "options" import parameter is used to capture them. VERSION
$Revision: 1.18 $ AUTHOR
Colin Robertson <cpan _at_ bbc _dot_ co _dot_ uk> COPYRIGHT
(c) BBC 2005-6. This program is free software; you can redistribute it and/or modify it under the GNU GPL. See the file COPYING in this distribution, or http://www.gnu.org/licenses/gpl.txt perl v5.10.0 2006-08-10 Test::Assertions::TestScript(3pm)
All times are GMT -4. The time now is 10:49 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy