I have cygwin bash.sh file that contains the following:
bash.sh:
cd "data processing"
"data processing" at the same directory of bash.sh
I'm trying to run this bash file from cmd not cygwin for some reason.
First, I've updated the path environment variable with cygwin bin directory.
cmd command:
cd "<the-bash-file-directory>"
bash --login -c "bash '<the-bash-file-directory>\\bash.sh'"
then it gives me that error:
error
cd: data processing: No such file or directory
I'm a beginner in using cmd and cygwin and really stuck lots of the time at running things from each other and conflating paths!
Because bash.sh isn't being run from <the-bash-file-directory>. It's being run from your home directory. The --login switch is causing that to happen. You need to do something like this:
bash --login -c "cd <the-bash-file-directory> && ./bash.sh"
or get rid of the --login switch if you can:
cd "<the-bash-file-directory>"
bash -c "./bash.sh"
Related
I am new to bash and trying to run the following script on Git Bash for Windows, on Windows Server 2022:
"C:\Program Files\Git\bin\bash.exe" -c C:/Users/agentSvc/AppData/Roaming/Composer/vendor/debricked/cli && php bin\console debricked:scan '' 123 gitHubOrg/repoName 456 https://github.com/repo local
I have falsified some of the values.
The documentation is here:- https://debricked.com/docs/integrations/cli.html
However, I get errors such as "Is a directory", etc. What is the correct syntax here? I am trying to change directory as per the documentation and then run the command.
I would like to automatize a process running a .bat file but using the bash terminal in my WSL2. These are my commands in my .bat:
bash
cd ~/Dev/Folder
nvm use 14.15.0
npm start
But the .bat stops after running "bash". I also tried with bash && cd ~/Dev/Folder && nvm use 14.15.0 && npm start and also replacing "bash" with "wsl", but same result.
Maybe I'm doing something wrong, so I would appreciate some help with this.
bash starts a new Bash shell and waits for it to exit, like for any other terminal command. The subsequent commands are not redirected to Bash - they'll be executed once the Bash process exits.
To run commands within Bash, use the -c flag:
bash -c "cd ~/Dev/Folder && ls && nvm use 14.15.0 && npm start"
Also see What does 'bash -c' do?.
The following simple script is apparently not so simple.
The entire script appears to work properly until I get to the npm command.
I have looked at the numerous threads here, but none of the solutions fix the issue.
Each of the scripts is kicked off by a parent script.
Here is the parent:
#!/bin/bash/
authGogglesPath='/c/sandBox/amazon-sandbox/CraigMonroe/platform.shared.auth-goggles'
echo $'\nExecuting node commands for local running solution...\n'
#echo $(pwd)
# run the scripts
bash edge.sh ${edgePath} &
exec bash
I checked my path in the terminal and it's aware
I thought that it might be running as another associated profile so I tried the full path to npm, but the same results.
#!/bin/bash/
authGogglesPath='/c/sandBox/amazon-sandbox/CraigMonroe/platform.shared.auth-goggles'
echo $'\nExecuting node commands for local running solution...\n'
#echo $(pwd)
# run the scripts
bash edge.sh ${edgePath} &
exec bash
That calls edge.sh with a string path for arg (more for later)
edge.sh is another simple script
#!/bin/bash/
PATH=$1
#echo $PATH
if [ -z "${PATH}" ] ; then
"PATH is empty! Aborting"
exit 1
fi
cd "${PATH}"
echo $'\nExecuting Edge...\n'
npm run dev
Each time I run this I'm receiving:
$ bash edge.sh /c/sandBox/amazon-sandbox/CraigMonroe/platform.shared.auth-goggles/
Executing Edge...
edge.sh: line 13: npm: command not found
cmonroe#LP10-G6QD2X2 MINGW64 ~/cruxScripts
$
When in the terminal and manually navigating to the directory and running the command it works properly. Where the edge builds and starts.
Unless npm is in /c/sandBox/amazon-sandbox/CraigMonroe/platform.shared.auth-goggles/, doing PATH=$1 means your PATH only refers to that one folder.
No more /usr/bin or any other folders your bash session might need.
As commented, adding to the PATH should work
PATH="$1:${PATH}"
I am trying to run a bash script which contains few commands to execute. I want to open a terminal and execute multiple commands into it. I have written commands to set the directory path and want to make a folder there.
Code :
gnome-terminal --working-directory=/var/run/
gnome-terminal -e "bash -c \"sudo mkdir sphinxsearch; exec bash\""
Here, There are 2 problems :
1) Two separate terminal are opened that I don't want. I need only a single terimal where I will execute my commands.
2) sudo mkdir sphinxsearch folder is created at the default path from where I am executing my bash script. I need to create a folder inside /var/run/
Each invocation of gnome-terminal will open a separate terminals.
Try this:
gnome-terminal --working-directory=/var/run/ -e "bash -c \"sudo mkdir sphinxsearch; exec bash\""
Here i am combining both options in a single invocation of gnome-terminal
sudo mkdir /var/run/sphinxsearch;
will create the folder in /var/run/
I was trying the below program,
This is a simple script, to cd into a folder
#! /bin/bash
cd /root/
But this below command , doesnt get into the folder
EDITED
#!/bin/bash
alias ex="cd /fs/fm"
alias ex1="source setenv"
alias ex2="cd /fs/fm/tests"
alias ex3="runtest"
To get into /root/ you should make sure that you have permissions. It's accessible if you're running as root itself but if you're running as a normal user you should consider becoming root first. One way is to use sudo:
sudo bash script.sh
And again, make sure your script is in UNIX format. Certainly you can't change to /root/\r.
sed -i 's|\r||' script.sh
dos2unix script.sh
This will never work The script you're running is a separate process, when it finishes you get back to the original environment (cwd, enviroment variables, etc...).
Create an alias:
alias r="cd /root"
or execute the script within your shell:
. myscript
Note: . is a synonym for source.