How to check the result of an operation?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to check the result of an operation?
# 1  
Old 11-16-2011
How to check the result of an operation?

Hi,

This is probably very basic but I couldn't find an answer looking around.

In a Linux script how to get the result of an operation? I want to create a folder if it does not exist.
That I found I can do:
PHP Code:
test -e folder_name || mkdir folder_name 
Now if the folder was created how can I get a confirmation? A true or false result from the mkdir. I want to log the operations that the script will be doing. Or a result from the test operation.

Thanks.

---------- Post updated at 03:31 AM ---------- Previous update was at 03:09 AM ----------

Ok I think I got it now.

PHP Code:
test -d folder_name
echo $? 
$? will contain 0 or 1 depeding on the result.

I wonder if that is the best way though.

Last edited by gunsnrails; 11-16-2011 at 04:24 AM..
# 2  
Old 11-16-2011
you can simply try this Smilie
Code:
if [ -e folder_name ] ; then 
if [ -f folder_name ] ; then echo "is a file"
elif [ -d folder_name ] ; then echo "is a direc"
else echo "is not file/dir"; fi
else echo "folder_name is not exist"; fi

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk script to check and throw error for multiplication result

I need to multiply column1 and column3 data and need to compare it with column5. Need to check multiplication and Throw error if result is greater or less than column5 values, though difference of +/- 2 will be ok Ex - if column1 has 2.4 and column3 has 3.5, it will be ok if column5 have value... (13 Replies)
Discussion started by: as7951
13 Replies

2. Shell Programming and Scripting

How to compare the current result with previous line result.?

Hi Gurus, I have requirement to compare current result with previous reuslt. The sample case is below. 1 job1 1 1 job2 2 1 job3 3 2 job_a1 1 2 job_a2 2 2 job_a3 3 3 job_b1 1 3 job_b2 2 for above sample file, GID is group ID, for input line, the job run... (1 Reply)
Discussion started by: ken6503
1 Replies

3. Shell Programming and Scripting

Need to check file space requirements prior to operation

I'm all done with a script that relocates some files from different directories to another, just one caveat; I need it to check if i have enough space to complete the operation. On my commandline i normally use df -h /dir/im/checking | awk '{print $4}' | grep -v Avail I'd like to have my script... (3 Replies)
Discussion started by: DC Slick
3 Replies

4. Shell Programming and Scripting

Column operation : cosne and sine operation

I have a txt file with several columns and i want to peform an operation on two columns and output it to a new txt file . file.txt 900.00000 1 1 1 500.00000 500.00000 100000.000 4 4 1.45257346E-07 899.10834 ... (4 Replies)
Discussion started by: shashi792
4 Replies

5. Shell Programming and Scripting

Mail::Sender - How to Check Result Code?

I have a code block which sends a mail using Mail::Sender. Everything works great now. I just want to know how to check whether the status of sending mail is success or failure. Based on which I will log the result in my log file. How can I do this? Any idea please? (2 Replies)
Discussion started by: dahlia84
2 Replies

6. Shell Programming and Scripting

sed OR-Operation

Hello, I'm trying to get the configuration-IP-Addresses from Cisco-configurations on the Routers they are defined as a Loopback0-interface like this: interface Loopback0 ip address 172.23.19.249 255.255.255.255 On the Switches they are defined as a VLAN 80 interface like this ... (4 Replies)
Discussion started by: Sally[-_-]
4 Replies

7. Shell Programming and Scripting

String Operation

/home8/mc09ats/UnixCw/file4 this is the path...i have 2 variables filename and filepath...i want filename=file4 filepath=/home8/mc09ats/UnixCw i.e. i think i have to find last occurence of "/" in string and the string after "/" want to take in some variable and string before last "/"... (4 Replies)
Discussion started by: AbhijitIT
4 Replies

8. UNIX for Dummies Questions & Answers

string operation

I am trying to ask for full name in a script, Then echo back to the user with the surname only, omitting the first name. Thanks (2 Replies)
Discussion started by: orjnet
2 Replies

9. UNIX for Dummies Questions & Answers

display the result of wc -l with words before and after the result

hello showrev -p | wc -l returns: 381 What to do in case I want to have this output: number of lines returned by showrev -p is: 381 thx (3 Replies)
Discussion started by: melanie_pfefer
3 Replies

10. Shell Programming and Scripting

Outputting formatted Result log file from old 30000 lines result log<help required>

Well I have a 3000 lines result log file that contains all the machine data when it does the testing... It has 3 different section that i am intrsted in 1) starting with "20071126 11:11:11 Machine Header 1" 1000 lines... "End machine header 1" 2) starting with "20071126 12:12:12 Machine... (5 Replies)
Discussion started by: vikas.iet
5 Replies
Login or Register to Ask a Question