cd

“cd” does not work in shell script

陌路散爱 提交于 2019-11-29 16:01:48
问题 I am wondering why cd does not work in shell script. It is as follows, #!/bin/sh cd test mkdir $(date +%d-%mm-%Y) When I run this, I get can't cd to test cd: 2: can't cd to /test Why is it like this? 回答1: I had the same problem. Turned out the problem was \r\n line endings. To fix it, do tr -d "\r" < oldname.sh > newname.sh From http://talk.maemo.org/showthread.php?s=1cadd53b369d5408c2b9d53580a32dc4&t=67836&page=2 回答2: Not really relevant for this question. I had the same error message,

One command to create and change directory

不打扰是莪最后的温柔 提交于 2019-11-28 07:12:01
I'm searching for just one command — nothing with && or | — that creates a directory and then immediately changes your current directory to the newly-created directory. (This is a question someone got for his exams of "linux-usage", he made a new command that did that, but that didn't give him the points.) This is on a debian server if that matters. Marian Zburlea I believe you are looking for this: mkdir project1 && cd "$_" define a bash function for that purpose in your $HOME/.bashrc e.g. function mkdcd () { mkdir "$1" && cd "$1" } then type mkdcd foodir in your interactive shell So stricto

Open CD/DVD door with a Windows API call?

拈花ヽ惹草 提交于 2019-11-28 05:19:04
问题 How do I open the CD/DVD door with a Windows API call? 回答1: If you're using .NET this will work: http://www.dotnetspider.com/resources/15834-eject-close-cd-tray.aspx It was the first link to come up when I googled "win api open cd door". This was the second one: Windows CDROM Eject. 回答2: If anyone else is interested, here is a short draft of how it can be done in Lua: require ("alien") local kolbasz = alien.winmm.mciSendStringA kolbasz:types{ ret = 'long', abi = 'stdcall', 'string', 'string',

How to run 'cd' in shell script and stay there after script finishes?

时光毁灭记忆、已成空白 提交于 2019-11-27 18:15:33
I used 'change directory' in my shell script (bash) #!/bin/bash alias mycd='cd some_place' mycd pwd pwd prints some_place correctly, but after the script finished my current working directory doesn't change. Is it possible to change my path by script? You need to source the file as: . myfile.sh or source myfile.sh Without sourcing the changes will happen in the sub-shell and not in the parent shell which is invoking the script. But when you source a file the lines in the file are executed as if they were typed at the command line. The script is run in a separate subshell. That subshell changes

Change directory command in Docker?

心已入冬 提交于 2019-11-27 17:45:39
In docker I want to do this: git clone XYZ cd XYZ make XYZ However because there is no cd command, I have to pass in the full path everytime (make XYZ /fullpath). Any good solutions for this? You can run a script, or a more complex parameter to the RUN. Here is an example from a Dockerfile I've downloaded to look at previously: RUN cd /opt && unzip treeio.zip && mv treeio-master treeio && \ rm -f treeio.zip && cd treeio && pip install -r requirements.pip Because of the use of '&&', it will only get to the final 'pip install' command if all the previous commands have succeeded. In fact, since

How do I find the current directory of a batch file, and then use it for the path?

折月煮酒 提交于 2019-11-27 12:16:18
I have a batch file that I intend to distribute to our customers to run a software task. We distribute them as a folder or .zip with the files inside. Inside, there is the batch files and another folder with the files needed to run the batch. Normally, when you make a batch, you type the path where the files are. But I won't know where the files are. The files will still be kept inside the master folder, but I need to have the batch find that folder to run the files. So for example: If they have the master folder on the desktop and they run it, it would need to be something like "C:\Users

Execute a bash function upon entering a directory

别等时光非礼了梦想. 提交于 2019-11-27 10:56:34
问题 I'd like to execute a particular bash function when I enter a new directory. Somethink like: alias cd="cd $@ && myfunction" $@ doesn't work there, and adding a backslash doesn't help. I'm also a little worried about messing with cd, and it would be nice if this worked for other commands which changed directory, like pushd and popd . Any better aliases/commands? 回答1: The easiest solution I can come up with is this myfunction() { if [ "$PWD" != "$MYOLDPWD" ]; then MYOLDPWD="$PWD"; # strut yer

How to make an html page open automatically on a CD/DVD

十年热恋 提交于 2019-11-27 02:02:04
问题 I need to include an html page (table of contents) on a CD/DVD. I'd like the html page to open automatically when the user puts the CD/DVD in their machine. Is there a way to do this (the MSDN cds do this) either by purchasing software or otherwise? 回答1: I used (the free version of) AutoRunPro I remember when I was confronted with the problem once [autorun] shellexecute=path\to\htmlfile.html just wouldn't work on most PC's. I used a program called AutorunPro.EXE, just copied it in the root,

One command to create and change directory

帅比萌擦擦* 提交于 2019-11-27 01:34:31
问题 I'm searching for just one command — nothing with && or | — that creates a directory and then immediately changes your current directory to the newly-created directory. (This is a question someone got for his exams of "linux-usage", he made a new command that did that, but that didn't give him the points.) This is on a debian server if that matters. 回答1: I believe you are looking for this: mkdir project1 && cd "$_" 回答2: define a bash function for that purpose in your $HOME/.bashrc e.g.

How to run 'cd' in shell script and stay there after script finishes?

笑着哭i 提交于 2019-11-26 22:39:21
问题 I used 'change directory' in my shell script (bash) #!/bin/bash alias mycd='cd some_place' mycd pwd pwd prints some_place correctly, but after the script finished my current working directory doesn't change. Is it possible to change my path by script? 回答1: You need to source the file as: . myfile.sh or source myfile.sh Without sourcing the changes will happen in the sub-shell and not in the parent shell which is invoking the script. But when you source a file the lines in the file are