|
Home > Archive > Unix Shell > November 2006 > touch a file, creating the directory as we go
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
touch a file, creating the directory as we go
|
|
| spudtheimpaler@gmail.com 2006-11-29, 7:28 am |
| Hi,
First things first I can't use sed or awk, else I could have probably
found this out on my own.
I have made a function that I need to work on, which passes through a
filename which i then have to move to another directory at some point.
if the file is passed as "file" it works fine, as a different process
is initiated, however, if someone passes the argument in the format
"/home/bob.someone/work/this_folder_name_needs_to_remain/file" and i
want to move it to /somewhere/work/this_folder_needs_to_remain/file i
cannot mv it, as the this_folder_needs_to_remain/ folder hasn't yet
been initiated. as that whole tree is passed through as the argument, I
can't break it down, nor can i use awk or sed to strip the last /
The application is a recycle bin to replace the rm command.
"this must be homework!", I here you cry. It isn't. A company is
testing my scripting knowledge for a position and the app works fine
unless someone enters
rm_alternative /the/full/path/name/file
so to clarify i am passed "/some/path/here/file" - how do i extract the
"/some/path/here/" so i can use mkdir? I cant use touch or echo ""> as
the directory does not exist where i want to move the file to.
Thank you for your time,
Mitch.
Obviously you may not want to help me as I am being tested on this, but
I am looking for guidance or any help, not necessarily an answer.
| |
|
| spudtheimpaler@gmail.com wrote:
> Hi,
>
> First things first I can't use sed or awk, else I could have probably
> found this out on my own.
>
> I have made a function that I need to work on, which passes through a
> filename which i then have to move to another directory at some point.
>
> if the file is passed as "file" it works fine, as a different process
> is initiated, however, if someone passes the argument in the format
> "/home/bob.someone/work/this_folder_name_needs_to_remain/file" and i
> want to move it to /somewhere/work/this_folder_needs_to_remain/file i
> cannot mv it, as the this_folder_needs_to_remain/ folder hasn't yet
> been initiated. as that whole tree is passed through as the argument, I
> can't break it down, nor can i use awk or sed to strip the last /
>
> The application is a recycle bin to replace the rm command.
>
> "this must be homework!", I here you cry. It isn't. A company is
> testing my scripting knowledge for a position and the app works fine
> unless someone enters
>
> rm_alternative /the/full/path/name/file
>
> so to clarify i am passed "/some/path/here/file" - how do i extract the
> "/some/path/here/" so i can use mkdir?
Have a look at either the command 'dirname' (and the complementary
'basename') or alternatively the shell features about "variable
expansion", specifically ${var%pattern} (and the complementary
${var##pattern}).
Janis
> I cant use touch or echo ""> as
> the directory does not exist where i want to move the file to.
>
> Thank you for your time,
>
> Mitch.
>
> Obviously you may not want to help me as I am being tested on this, but
> I am looking for guidance or any help, not necessarily an answer.
| |
| spudtheimpaler@gmail.com 2006-11-29, 7:28 am |
|
Janis wrote:
> spudtheimpaler@gmail.com wrote:
>
> Have a look at either the command 'dirname' (and the complementary
> 'basename') or alternatively the shell features about "variable
> expansion", specifically ${var%pattern} (and the complementary
> ${var##pattern}).
>
> Janis
Perfect. exactly what i was looking for. I'm sure I can use them to
find what i need now.
Thanks!
Mitch
[vbcol=seagreen]
>
|
|
|
|
|