Mkdir fails when defined and called with functions.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Mkdir fails when defined and called with functions.
# 8  
Old 12-14-2016
Quote:
Originally Posted by Corona688
Then just use mkdir -p, which will not fail when directory already exists:

Code:
$ mkdir -p /tmp && echo "I did not fail"
I did not fail

$

I am working on someone else script.

The reason i was not sure of using the -p option is that the script has several mkdir commands only two of which has the -p option.

So, i was not sure if there if a purpose of not using the -p option.
# 9  
Old 12-14-2016
If mkdir is not supposed to fail when the folder already exists, -p is what you want. That's what it's for. It doesn't change it much beyond that.
# 10  
Old 12-15-2016
What if a file of the same name exists, e.g. /tmp/mytmp?

Not only will mkdir -p /tmp/mytmp fail, other subsequent commands like echo "Hello" > /tmp/mytmp/log will go wrong.

What if the directory exists, but you have no access to it? Trying to create files in it will fail.


You need some proper error checking and a better design.



Robin
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

[solved] awk: placement of user-defined functions

Hi folks, is there any recommendation, especially from a point of performance, about where to place a user-defined function in awk, like in BEGIN{} or if it is only need once at the end in END{}? Or doesn't it matter at all since, awk is so clever and only interprets it once, wherever it is... (3 Replies)
Discussion started by: zaxxon
3 Replies

2. Shell Programming and Scripting

How to execute functions or initiate functions as command line parameters for below requirement?

I have 7 functions those need to be executed as command line inputs, I tried with below code it’s not executing function. If I run the ./script 2 then fun2 should execute , how to initiate that function I tried case and if else also, how to initiate function from command line if then... (8 Replies)
Discussion started by: saku
8 Replies

3. Shell Programming and Scripting

User defined functions in awk

Hi; Is der ne to to use user defined functions for the values in awk find $1 -type f -ls | nawk '{{print "|"$3"|"$5"|"$6"|"$8"|"$9"|"$10"|"} for(i=11;i<=NF;i++){printf("%s",$i)}}' In above command i want to append some values returned by user functions on line. thnks; ajay (1 Reply)
Discussion started by: ajaypadvi
1 Replies

4. Shell Programming and Scripting

Perl script to find where functions is called in c

Hello, I need to write a perl script to find where functions is called in c files.. The script should scan the file and find out the function names and then search to see where they are called... Lets for now assume all functions are internal. I don't know where to start :( ... (4 Replies)
Discussion started by: bojomojo
4 Replies

5. Emergency UNIX and Linux Support

Functions defined in header / cpp file behaves different

File: A.h class A { public: struct x X; int show() { x.member_variable ? 0: -1; } }; Now if A.cpp is complied which includes A.h (which is actually in a huge project space) we see that x.member_variable value is not as expected. But if remove the show() method and place... (4 Replies)
Discussion started by: uunniixx
4 Replies

6. UNIX for Dummies Questions & Answers

Expect "interact" fails when called from another script

So, I have an expect script (let's call it expect.exp) that takes 3 arguments. It logs into a remote server, runs a set of commands, then hands control over to the user by the "interact" command. If I call this script from the command line, it works properly. Now I'd like to apply this script... (2 Replies)
Discussion started by: treesloth
2 Replies

7. Shell Programming and Scripting

user-defined functions, "$@", $jobs and $ps wwaxu

Imagine a user-defined function. func() { /usr/pkg/bin/program long-string-of-switches-and-configs "$@" ;} I execute it once. Then background it. I execute another instance. Then bg it. func unique-user-input ^Z func unique-user-input ^Z First I view with ps ps wwaux ... (0 Replies)
Discussion started by: uiop44
0 Replies

8. Shell Programming and Scripting

Shell Script to display function names (called & defined) in a C++ Source Code

Hello to all, I am looking for a way to display only the names of function (calls & definition) of a C++ source code.There is already a post related to this, but the script is to find the functions using a specific variable, and the replies are not that convincing since they cannot be used for... (2 Replies)
Discussion started by: frozensmilz
2 Replies

9. UNIX for Dummies Questions & Answers

finding called functions recursively

I want to write a shell script which traverses a cpp file. Suppose there is function fncn_name6 .. which is called by fncn_name5 which in turn called by fncn_name4 and so on .. in a single cpp class. ie fncn_name1 { fncn_name2 { fncn_name3 } { fncn_name4 } } so fncn_name1 is... (2 Replies)
Discussion started by: ultimatix
2 Replies

10. Windows & DOS: Issues & Discussions

Samba (SMB) client fails: "Called name not present"

Hi, I issue smbclient on a Linux REd hat server : smbclient -L ***.16.0.42 -U domaine/Administrator Password: Domain= OS= Server= Domain= OS= Server= Sharename Type Comment --------- ---- ------- IPC$ IPC IPC distant ... (0 Replies)
Discussion started by: big123456
0 Replies
Login or Register to Ask a Question