Explanation Bash Command ${PATH}: - terminal

To make shortcut for command line function to make it available everywhere in my mac i usually add this line in ~/.bash_profile
To include one terminal execution file, i usually use: alias yiic='~/Script/Yii/1.1.13/yiic'
yiic is terminal execution file.
And then now i have example this from another site: export PATH=${PATH}:/development/sdk/android-sdk-macosx/tools
I understand this command like import all execution file in tools directory, but what is the meaning of ${PATH}: ?

${PATH} is the other folders that your computer will look in. It's automatically set up by your OS. If you do the following command in your Terminal, you'll see all the folders your computer looks in:
echo $PATH

Related

Running shell script on Windows via Cygwin mintty.exe doesn't execute runcoms

Problem summary
I'm trying to launch a .sh script via Windows 10 Cygwin (i.e. mintty.exe > bash.exe) but neither .profile, .bash_profile, or .bashrc are loading, which I need to update PATH env variable with Cygwin's bin directory.
Background
I'm trying to launch a script finder.sh:
#!/bin/bash
find .
read
from C:\Users\Bo\Temp\. It has unix line endings and executable bit set.
I have Cygwin installed at C:\Users\Bo\AppData\Local\Programs\cygwin64\. I do not have this path in either System or User Windows' Environment Variables (and I don't want to!). My runcoms all live in this directory under /home/Bo. My .bash_profile (and ATM .bashrc) have an export PATH="/cygdrive/c/Users/Bo/AppData/Local/Programs/cygwin64/bin":${PATH} in them.
I want to launch the script from Windows Explorer. I tried using the bash.exe and mintty.exe in the cygwin64\bin\ folder via Open > Choose another app > More apps > Look for another app on this PC. In either case the mintty window displays:
FIND: Parameter format not correct
meaning the Windows' find command was used not Cygwin's. So I have my script echo $PATH and the Cygwin/bin directory is not in PATH. If I add the proper export PATH statement from above to my own script it works fine. So, now to debug the launcher and runcoms...
I've put echo ${0} statements in .profile, .bash_profile, and .bashrc, none of which trigger which I run the .sh script, they are never run. I've read SO and the mans. I've tried creating a Shortcut to both mintty.exe and bash.exe passing a variety of -l -i -e - commands to each using Properties > Shortcut > Target and they are never run. E.g. running simply [..]\mintty.exe -h always doesn't even leave the window open.
How do I get my script to run in Windows Explorer via Cygwin's mintty.exe/bash.exe, and to read from a runcom to update PATH (to find Cygwin Linux commands, vs. updating Windows Environment Variable)?
Two part fix:
A) set a Windows Environment Variable for BASH_ENV to a .bash_env under your Cygwin HOME, and export the PATH variable to include the Cygwin/bin directory from that file. I cannot find a decent reference for this in Cygwin documentation because it seems to be simply a bash thing, but this variable is what bash looks for when running non login/interactively. Best reference: Cygwin shell doesn't execute .bashrc.
And B) run the .sh with bash.exe from Cygwin/bin using Open With....
ALSO, annoying Windows bug: when you select a program to Open With... your .sh script, it will always run 1x with a CWD from your C:\Windows\System32 directory(?!) and all other times will run fine with the CWD as the directory from your .sh script.

navigate through folders using shell script

I am new to shell scripting. I have saved the script file as script_hdl in my home directory. From my home directory, I want to navigate using the script in the following order: cd ../../site/edu/ess/project/user/rark444
and then open a new tab from this new location in the terminal.
I used this as my script:
#!/bin/bash
alias script_hdl="cd ../../site/edu/ess/project/user/rark444"
I run the script like this
./script_hdl
But I don't see any response in the terminal. I feel I am missing something but I don't know what is it. Thanks in advance for your help.
You have two ways to change directory here.
Script
The first one is to write a script, in such a way that you can run other command after cd. It works without the alias command: let's say you remove it.
cd command is proper to the running process. When you execute your script, the following happen:
your shell spawns (forks as) a new shell process executing your code. The main process wait for its child to finish;
this new child process actually does change its own working directory with your cd command, then quits (it's over)
the original shell process stops waiting and prints the prompt again. But this process has not changed directory (only the child process did)
To perform what you want, (remove the alias command, then) call your script as follows:
source script_hdl
or with following shortcut:
. script_hdl
meaning that you want the instructions to run in the same shell process.
Alias
The second way to change directory is to use an alias. But you should not write your alias definition in a random script file, add it in your ~/.bashrc instead (this file is run each time you open a shell).
So:
alias script_hdl="cd ../../site/edu/ess/project/user/rark444"
to reload ~/.bashrc:
. ~/.bashrc
And then don't try to execute from the file, just launch your alias as if it was a normal command:
script_hdl
Looks like you are trying to set up an alias. You can do this by editing your .bash_profile file in your home directory (if it's not there you can create one and then run "source .bash_profile" after editing it) and make an entry like alias script_hdl='cd ../../site/edu/ess/project/user/rark444' and then run "script_hdl" from your terminal.
For more info on alias you can follow the link mentioned by Paul.
Make sure the spelling is correct as unix is case sensitive and that you have permissions. First try it on the command line to ensure that it works, if there is an error it will appear on the command line as sometimes scripts hide the errors and messages. If it works then copy the text to the script file and don't use alias.
Here is the correct usage of alias
https://en.wikipedia.org/wiki/Alias_(command)

How to run mysqldump under XAMPP on Mac OS

I want to run the mysqldump command in Mac OS, I am able to find the location of the file as "/Application/XAMPP/xamppfiles/bin".
But don't know how to exec the same from command prompt, as it says command not find, by simply typing it and executing it from the prompt/
The trick on *NIX systems when executing things is that you have to tell the shell exactly where the file is, or it must be in your $PATH.
This should work:
/Application/XAMPP/xamppfiles/bin/mysqldump
This would also work:
cd /Application/XAMPP/xamppfiles/bin/
./mysqldump
If you want to make it so you can just type the command without giving the location, add it to your PATH variable:
export PATH=$PATH:/Application/XAMPP/xamppfiles/bin
And then just run it!
mysqldump
Also on Mac you can simply drag and drop the file from finder right into the terminal. This will automatically type the path for you.

How To Add A Script To Add Functionality To the Terminal?

I have a small perl script ( found here ) which adds command line functionality to an application I already have installed, Coda. Basically it will open a file with the application when I type:
coda filename.py
Where (on OSX) do I need to put this file to make it function? Do I need to do anything else to my environment to get this working?
Type echo $PATH at the terminal. You will get back a series of paths separated by colons. The file needs to be placed into one of those folders. The file also needs to have the execute flag set, which is done with the chmod tool.

cywin bash script command not found when called from batch

#!/bin/bash
echo "Testing"
cd "/cygdrive/x/Internal Communications/Riccardo/"
filename=htdocs-`date +%A`.tar.gz
tar cvzf $filename "/cygdrive/c/Program Files/Zend/Apache2/htdocs"
The above script is working when it is called inside cygwin console, but when I try to call it from a batch file I get "command not found" for date and tar command. I think that bash.exe does not have the PATH set up.
I need to run that script from that batch file because I want to add the script to the task scheduler.
As has already been said, you need to add the Cygwin binaries to your path. To do so, right click on "My Computer", click "Properties", then "Advanced", then "Environment Variables".
Create a new environment variable with name "CYGWIN_HOME" and value "C:\cygwin" (or wherever you installed cygwin. The default location is "C:\cygwin\" so this should probably work for you).
Then edit the environment variable named "PATH", and tack on the following to the end:
;%CYGWIN_HOME%\bin;%CYGWIN_HOME%\sbin;%CYGWIN_HOME%\usr\bin;%CYGWIN_HOME%\usr\sbin;%CYGWIN_HOME%\usr\local\bin;%CYGWIN_HOME%\usr\local\sbin
Close your command prompt, then reopen it. The cygwin binaries should now be available. You can double-check this by typing "which bash". It should report the location of your bash executable.
FWIW, Cygwin has cron.
Are you calling your script like this?
bash --login -i ./myscript.sh
Put your cygwin bin directory (likely C:\cygwin\bin) on your PATH environment variable.
This would also give you the benefit of being able to use commands like tar, ls, rm, etc. from a regular console windows and not just a Cygwin console.
If this script is invoked from a Windows command shell, the first line will result in an error since #!/bin/bash is not a recognized Windows command and # is not a valid comment delimiter in a batch file.
So, the bottom line is that this script runs as a regular batch file rather than from within Cygwin's bash. As noted by matt b, you likely do not have the Cygwin executable path in your PATH environment variable. Without this, the batch file cannot find the Cygwin utilities (tar and date).
I just had this problem.
Editing the environment variable works great. But if you are have no admin rights you can´t do that.
In this case you can execute your commands by using the absolute path like:
/usr/bin/tar cvzf $filename
/usr/bin/cat $filename
If you do so your bash script works even if you call it from a batch file.

Resources