With bash I can create a directory and immediately enter it with mkdir mydir && cd $_. Is there a powershell equivalent of $_?
Equivalent of "&& cd $_" in Powershell
658 views Asked by Dominik At
1
There are 1 answers
Related Questions in POWERSHELL
- Where is the AMPathPopUpButton class declared?
- Get volume paths on Automator shell service
- Applescript saving lines in document as variables
- Resize images to specific width only (AppleScript or Automator)
- Create ppsx from pdf
- How to make Mac Application (use Automator) which convert image file of PDF to eps file with ImageMagick
- Is there a way to convert markdown to interpreted RTF?
- cd into /Contents/ in Automator
- OS X - Drag URL / weblog to finder generates PDF of web page
- Find and Paste Apple Script
Related Questions in PARAMETERS
- Where is the AMPathPopUpButton class declared?
- Get volume paths on Automator shell service
- Applescript saving lines in document as variables
- Resize images to specific width only (AppleScript or Automator)
- Create ppsx from pdf
- How to make Mac Application (use Automator) which convert image file of PDF to eps file with ImageMagick
- Is there a way to convert markdown to interpreted RTF?
- cd into /Contents/ in Automator
- OS X - Drag URL / weblog to finder generates PDF of web page
- Find and Paste Apple Script
Related Questions in MKDIR
- Where is the AMPathPopUpButton class declared?
- Get volume paths on Automator shell service
- Applescript saving lines in document as variables
- Resize images to specific width only (AppleScript or Automator)
- Create ppsx from pdf
- How to make Mac Application (use Automator) which convert image file of PDF to eps file with ImageMagick
- Is there a way to convert markdown to interpreted RTF?
- cd into /Contents/ in Automator
- OS X - Drag URL / weblog to finder generates PDF of web page
- Find and Paste Apple Script
Related Questions in CD
- Where is the AMPathPopUpButton class declared?
- Get volume paths on Automator shell service
- Applescript saving lines in document as variables
- Resize images to specific width only (AppleScript or Automator)
- Create ppsx from pdf
- How to make Mac Application (use Automator) which convert image file of PDF to eps file with ImageMagick
- Is there a way to convert markdown to interpreted RTF?
- cd into /Contents/ in Automator
- OS X - Drag URL / weblog to finder generates PDF of web page
- Find and Paste Apple Script
Related Questions in AUTOMATIC-VARIABLE
- Where is the AMPathPopUpButton class declared?
- Get volume paths on Automator shell service
- Applescript saving lines in document as variables
- Resize images to specific width only (AppleScript or Automator)
- Create ppsx from pdf
- How to make Mac Application (use Automator) which convert image file of PDF to eps file with ImageMagick
- Is there a way to convert markdown to interpreted RTF?
- cd into /Contents/ in Automator
- OS X - Drag URL / weblog to finder generates PDF of web page
- Find and Paste Apple Script
Popular Questions
- How do I undo the most recent local commits in Git?
- How can I remove a specific item from an array in JavaScript?
- How do I delete a Git branch locally and remotely?
- Find all files containing a specific text (string) on Linux?
- How do I revert a Git repository to a previous commit?
- How do I create an HTML button that acts like a link?
- How do I check out a remote Git branch?
- How do I force "git pull" to overwrite local files?
- How do I list all files of a directory?
- How to check whether a string contains a substring in JavaScript?
- How do I redirect to another webpage?
- How can I iterate over rows in a Pandas DataFrame?
- How do I convert a String to an int in Java?
- Does Python have a string 'contains' substring method?
- How do I check if a string contains a specific word?
Popular Tags
Trending Questions
- UIImageView Frame Doesn't Reflect Constraints
- Is it possible to use adb commands to click on a view by finding its ID?
- How to create a new web character symbol recognizable by html/javascript?
- Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
- Heap Gives Page Fault
- Connect ffmpeg to Visual Studio 2008
- Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
- How to avoid default initialization of objects in std::vector?
- second argument of the command line arguments in a format other than char** argv or char* argv[]
- How to improve efficiency of algorithm which generates next lexicographic permutation?
- Navigating to the another actvity app getting crash in android
- How to read the particular message format in android and store in sqlite database?
- Resetting inventory status after order is cancelled
- Efficiently compute powers of X in SSE/AVX
- Insert into an external database using ajax and php : POST 500 (Internal Server Error)
There are a few ways to do this. Remember that
cdis an alias for theSet-Locationcmdlet.Pipe the newly-created directory to
cdNotice that after running the command the current location uses the directory's provider path.
If you don't like the visual clutter, you could instead...
Pass the newly-created directory to
-PathVia a delay-bind script block
-Pathmust be specified as a named parameter for this to work.Via a direct parameter value
...or simply...
Pipe the newly-created directory's
FullNameproperty tocdIn a comment @zett42 suggests...
...which is a shorter way of writing...
...and works the same as...
...and much the same as...
Use
ForEach-Objectto pass the$_automatic variable to bothmkdirandcdIn this answer to Create new directory and navigate into it (Windows CMD) @Shenk suggests...
...which can be simplified to...
...and is much the same as...
Considerations
Notice that, unlike the other solutions, because the output of
mkdiris not captured by a variable, pipeline, parameter, etc. it is written to the console. If this is undesirable, you'll need to explictly suppress that output with something like......or...
Also, if
mkdirfails thencdcould be unconditionally executed, anyways. For example, this......produces two errors, not one, after the directory could not be created due to an invalid name, and this...
...changes the current directory even after
mkdirfailed to create a directory that already exists.