What you are running into is a classic misunderstanding of current working directory in relation to a process. Your shell process has a working directory which is inherited by any process (command) that is started by the shell. The child process may change its current working directory, but that will not affect the shell's current working directory. If you think about it, it doesn't make any sense for a child process to mess with the parent's environment.
While the cd command doesn't look any different than a normal command, it is a shell 'built-in' which in other words is a directive to the shell causing the shell to change it's environment, and does not cause a child process to be created. This is how you are able to cause the current working directory to change in the shell.
If you are looking to perform some operation given a username@hostname:path, and have the results of the operation go into the directory on the local system using just path, then just write a script to do it. If you want the current working directory to be changed in the local shell after the command has executed, unless there is magic that I am unaware of, it cannot be done.
Here's an example of a script that will suss out the path, change the directory to the path, and then copy via scp all files from the matching path on the remote machine to the local host. It' may not be exactly what you are looking for, but it will give you an idea of how to go forward.
If you save the script in a file ($HOME/bin/copy_from for example), then this command will run the script and copy the files to the path /tmp/foo/bar:
I have a variable and assigned the following values
***XYZ_201519_20150929140642_20150929140644_211_0_0_211
I need to read this variable from backward and stop read when I get first underscore (_)
In this scenario I should get 211
Thanks
Kris (3 Replies)
I need some help. I would like to read in a text file.
Take a variable such as ROW-D-01, compare it to what's in one line in the text file such as PROD/VM/ROW-D-01 and only input PROD/VM into a variable without the /ROW-D-01.
Is this possible? any help is appreciated. (2 Replies)
Hi,
I have 80 large files, from which I want to get a specific value to run a Bash script. Firstly, I want to get the part of a file which contains this:
Name =A
xxxxxx
yyyyyy
zzzzzz
aaaaaa
bbbbbb
Value = 57
This is necessary because in a file there are written more lines which... (6 Replies)
Hi
i have a file which has mutiple line in it.
inside that i have a pattern similar to this
/abc/def/hij
i want to fine the pattern starting with "/" and get the first word in between the the symbols "/" i.e. "abc" in this case into a variable.
thanks in advance (13 Replies)
Hi,
I'm using bash and brand new to shell script. I would like to do the following.
I have a string which is "UPDATE=1.0". I would like to read the value "1.0" alone in a variable. i.e the things afer "=" How do I do that?
Thanks, (1 Reply)
I may not being doing this description justice, but I'll give it a try.
I created a mailx script; there will be several messages using the same script where the only difference is the content. So I figured I'd make the content of the message a variable retrieved from a separate file. I have five... (5 Replies)
Hi,
i was using a input file to get the last line of the file.But now i have stored
the values from the file to a variable and want the last line from the variable . Slightly confused on how to extract that data from the variable.
previous code,
cat input.txt
<TIME>00:15:48</TIME>... (2 Replies)
I have following strings in a file
DUPTASMTRMMBAL,20070416200704160117232101172321,,,,,,,@@@Y
DUPTASMTRMMCON,20070416200704160127189901271899,,,,,,,@@@Y
DUPTASMTRMMHG,,20070416200704160112051001120510,,,,,,,@@@Y
What i need to do is replace the date 20070416 with anoth date which is stored in... (4 Replies)