Is it OK to overwrite a file created by mktemp?
Clash Royale CLAN TAG#URR8PPP
up vote
1
down vote
favorite
I'd like to copy a file to a temporary location.
I'd like to make sure I'm not overwriting anything important, and that I know the location of the file while the script is running.
#!/bin/bash
myfile="$(mktemp)"
cp "source" "$myfile"
# work with $myfile
rm "$myfile"
Does this seem OK? Is there anything I'm missing? (Permissions, etc.?)
I have a bad feeling about overwriting that file.
mktemp
add a comment |Â
up vote
1
down vote
favorite
I'd like to copy a file to a temporary location.
I'd like to make sure I'm not overwriting anything important, and that I know the location of the file while the script is running.
#!/bin/bash
myfile="$(mktemp)"
cp "source" "$myfile"
# work with $myfile
rm "$myfile"
Does this seem OK? Is there anything I'm missing? (Permissions, etc.?)
I have a bad feeling about overwriting that file.
mktemp
add a comment |Â
up vote
1
down vote
favorite
up vote
1
down vote
favorite
I'd like to copy a file to a temporary location.
I'd like to make sure I'm not overwriting anything important, and that I know the location of the file while the script is running.
#!/bin/bash
myfile="$(mktemp)"
cp "source" "$myfile"
# work with $myfile
rm "$myfile"
Does this seem OK? Is there anything I'm missing? (Permissions, etc.?)
I have a bad feeling about overwriting that file.
mktemp
I'd like to copy a file to a temporary location.
I'd like to make sure I'm not overwriting anything important, and that I know the location of the file while the script is running.
#!/bin/bash
myfile="$(mktemp)"
cp "source" "$myfile"
# work with $myfile
rm "$myfile"
Does this seem OK? Is there anything I'm missing? (Permissions, etc.?)
I have a bad feeling about overwriting that file.
mktemp
mktemp
asked Aug 23 at 21:01
user
1021111
1021111
add a comment |Â
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
4
down vote
accepted
From the man page
Create a temporary file or directory, safely, and print its name.
You could add a check for whether mktemp
was successful.
myfile="$(mktemp)"
if test $? != 0; then
exit 1
fi
If mktemp
succeeds, it has created a file that was not present before. You can safely overwrite that file, that is the purpose for using mktemp
. The permissions are set to u+rw
, as mentioned in the manual.
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
4
down vote
accepted
From the man page
Create a temporary file or directory, safely, and print its name.
You could add a check for whether mktemp
was successful.
myfile="$(mktemp)"
if test $? != 0; then
exit 1
fi
If mktemp
succeeds, it has created a file that was not present before. You can safely overwrite that file, that is the purpose for using mktemp
. The permissions are set to u+rw
, as mentioned in the manual.
add a comment |Â
up vote
4
down vote
accepted
From the man page
Create a temporary file or directory, safely, and print its name.
You could add a check for whether mktemp
was successful.
myfile="$(mktemp)"
if test $? != 0; then
exit 1
fi
If mktemp
succeeds, it has created a file that was not present before. You can safely overwrite that file, that is the purpose for using mktemp
. The permissions are set to u+rw
, as mentioned in the manual.
add a comment |Â
up vote
4
down vote
accepted
up vote
4
down vote
accepted
From the man page
Create a temporary file or directory, safely, and print its name.
You could add a check for whether mktemp
was successful.
myfile="$(mktemp)"
if test $? != 0; then
exit 1
fi
If mktemp
succeeds, it has created a file that was not present before. You can safely overwrite that file, that is the purpose for using mktemp
. The permissions are set to u+rw
, as mentioned in the manual.
From the man page
Create a temporary file or directory, safely, and print its name.
You could add a check for whether mktemp
was successful.
myfile="$(mktemp)"
if test $? != 0; then
exit 1
fi
If mktemp
succeeds, it has created a file that was not present before. You can safely overwrite that file, that is the purpose for using mktemp
. The permissions are set to u+rw
, as mentioned in the manual.
answered Aug 23 at 21:09
RalfFriedl
3,7451624
3,7451624
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f464506%2fis-it-ok-to-overwrite-a-file-created-by-mktemp%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password