When I write
mkdir("~/folder1" , 0777);
in linux, it failed to create a directory. If I replace the ~ with the expanded home directory, it works fine. What is the problem with using ~ ?
Thanks
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
~is known only to the shell and not to themkdirsystem call.But if you try:
this works as the
"mkdir ~/foo"is passed to a shell and shell expands~to$HOMEIf you want to make use of the
$HOMEwithmkdir, you can make use of thegetenvfunction as: