'Is there any copy paste environment variable for cmd and powershell?
Stage 1) say I wanna do the following:
%cd% | > clip <
[To copy the current path I am in right now in my CMD shell session]
(Useful info 1 I know the above code won't work as opposed to what it sounds like and to be more precise, it should be "CD | clip" to work that way, but lets assume for a second that there is an environment variable or something like a "%cd%" so that I can echo that or just a specific built-in command and whatsoever which can be used to output current working directory as a simple string (e.g "C:\Users\hello\there") to the std__exactly equivalent to what "pwd" in Unix-based operating systems does.)
Stage 2) And then I continue on to what follows:
cd | < clip >
[To paste what was copied on clipboard in stage 1]
(Useful info 2 Although I don't care about cd's functioning in this example, you can just think of "cd" at the start of the command in stage 2 as the change-directory function and not a thing outputting current working directory)
Question: What's the most similar default way of doing things like what is proposed in the example above, given that I'm not to use the Ctrl + Shift + V keyboard shortcut (say in windows terminal)?
I know how to do that in a Linux terminal but not in cmd shell. A little tip on that is more than appreciated:)
Solution 1:[1]
Here's what I can do in powershell:
Stage 1: copying the current path:
(pwd).path | scb
useful info:
- scb is an alias for "Set-Clipboard".
- The parenthesis in "(pwd)" is mandatory since we are running a pwd command within our whole command.
- ".path" is used to get the path as a simple string. Remember pwd in powershell outputs "Path----- C:\current\path". We only want the path and not the "Path------" part, so we have to use ".path". I hope it's clear.
Stage 2: going back one directory (only for demonstration purpose):
cd ..
Stage 3: reverting to the path copied in stage 1 (or even in another terminal session):
cd (gcb)
useful info
- gcb is an alias for "Get-Clipboard".
- Again parenthesis matters. In another words, "cd gcb" does NOT work.
PS: I think we can make a batch for that. for instance when starting a new terminal session, we won't have to type the complete path to navigate to the working directory in previous session. By the way, it still is a powershell method. I'd appreciate if someone could show me a similar way in pure cmd__if there is any.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
