Bash alias doesn't work in cygwin - bash

Can someone please explain to me how to set up bash aliases? I am using cygwin on windows 8.
I added alias my_first_alias='git status' at the end of /.bashrc file. Typing my_first_alias into cygwin results in -bash: my_first_alias: command not found.
Trying to restart cygwin, running . .bashrc doesn't help with that.

The syntax of your alias command is correct and should be working as long as the alias command is actually being executed. It sounds like your .bashrc file is not being loaded when you start your bash shell. Make sure you have the following in your ~/.bash_profile file:
[[ -s ~/.bashrc ]] && source ~/.bashrc
Also make sure that the location of .bashrc and .bash_profile are in your home directory. Above you have referenced /.bashrc. I doubt "/" is your home directory. You can determine the location of your home directory from the shell by entering the command:
cd; pwd

Related

ROS installation: no such file or directory

According to ros wiki, to set up environment,
I typed
echo "source /opt/ros/kinetic/setup.bash" >> ~/.bashrc
source ~/.bashrc
The error is
/opt/ros/kinetic/setup.bash:.:8: no such file or directory: /home/pikashun/setup.sh
In ~/.bashrc file, there is the source /opt/ros/kinetic/setup.bash line.
I use Ubuntu on WSL.
How can I improve?
Thank you!
I had the exact same issue. The problem is not due to setup.bash either ~/.bashrc but the shell that you are using. It turned out that you may be using a different shell than bash (i.e., zsh). When you are executing the setup.bash of ROS, zsh interprets the following command (whici is in /opt/ros/kinetic/setup.bash) differently:
_CATKIN_SETUP_DIR=$(builtin cd "`dirname "${BASH_SOURCE[0]}"`" > /dev/null && pwd)
It is setting the _CATKIN_SETUP_DIR to your user directory. That is why you are getting error, cause you using the wrong path:
/home/user/setup.bash instead of /opt/ros/kinetic/setup.bash
To check whether this is the issue of your problem, you can check the shell that you are using by execute the following in the terminal:
echo $0; echo $SHELL
It may return something like:
zsh
/bin/zsh
To switch from zsh to bash, use:
exec bash
Once done this, you can use source without any problem.
And to switch back to your previous shell (assuming that is zsh), just use:
exec zsh
The file /opt/ros/kinetic/setup.bash does nothing but loading /opt/ros/kinetic/setup.sh from the same directory. I might be that you are not running bash (check which terminal you run), or that WSL has some different behavoiour than expected.
However, your can just alter your append command like so:
echo "source /opt/ros/kinetic/setup.sh" >> ~/.bashrc
or in your case, since the entry exists already in your ~/.bashrc, edit the line source /opt/ros/kinetic/setup.bash to source /opt/ros/kinetic/setup.sh
The packages or files were not actually downloaded from the "http://wiki.ros.org/melodic/Installation/Ubuntu". To overcome this error first open terminal
check your directory pwd. If your directory is like /home/'Your PC Name' it won't actually work.
Change the directory : Type cd /
Continue the installation process from start which mentioned in "http://wiki.ros.org/melodic/Installation/Ubuntu"
melodic can change to kinetic or other version if you wish

.bashrc not sourced on Intellij IDEA's terminal

I have some aliased defined on my .bashrc that I'd like to use on my Intellij IDEA's terminal. Why is .bashrc not sourced?
.bashrc is only loaded when Bash is running in "interactive" mode. For some reason, IntelliJ defaults to running Bash in non-interactive mode, but this is easy to change. Open the IntelliJ Settings window, then open "Tools -> Terminal", and add -i to the Shell path.
(Note that in this screenshot, I have also changed the default shell, because I'm on a Mac, which makes it difficult to update /bin/bash. Unless you have installed a different version of Bash, do not blindly copy this change!)
Had the same issue with IntelliJ.
Solved this by setting the value /bin/bash --login in setting->Tools->Terminal->Shell path.
/bin/bash --login forces the bash to read the ~/.bash_profile.
https://intellij-support.jetbrains.com/hc/en-us/community/posts/205437150-Terminal-not-sourcing-bash-profile?page=1#community_comment_360000167679
In your home directory, add theses lines to .profile (create the file if it does not exist), in order to source .bashrc:
if [ "$SHELL" = "/bin/bash" ]; then
. ~/.bashrc
fi
For me, changing the line
Exec="/opt/idea-IU-183.4284.148/bin/idea.sh" %f
to
Exec=bash -ic "/opt/idea-IU-183.4284.148/bin/idea.sh" %f
worked. We exploit the hack that the interactive shell loads .bashrc :)
On Mac OSX Catalina, "/bin/bash" and ~/.zprofile worked for me:
Update:
Apple has changed the default shell to zsh. Therefore you have to rename your configuration files. .bashrc is now .zshrc and .bash_profile is now .zprofile.
My settings are in ~/.bash_profile . I solved it using:
echo "source ~/.bash_profile" >> .profile
sudo echo ". ~/.bashrc" >> /etc/bash.bashrc
Because > operator doesn't pass the sudo permissions to the write process.
I did this :
echo ". ~/.bashrc" | sudo tee /etc/bash.bashrc
I noticed that .bashrc isn't sourced only when I first install IntelliJ and run it directly via the idea.sh script in bin/.
Once I create the desktop entry via Tools -> Create Desktop Entry... and start it from the Ubuntu dash, .bashrc is sourced properly.
If you have recently moved to zsh from bash then go to ~/.zshrc file and update $PATH variable there:
Default value in .zshrc:
# If you come from bash you might have to change your $PATH.
# export PATH=$HOME/bin:/usr/local/bin:$PATH
Change to same PATH variable set in .bashrc and uncomment it
# If you come from bash you might have to change your $PATH.
export PATH=$HOME/bin:/usr/local/bin:<my-bash-paths>:$PATH
None of these answers worked for me. What did work is
sudo nano /etc/environment
...then manually adding my export and alias commands here to make them system wide.
But be careful, do NOT mess up the PATH or you'll have trouble logging back in to your desktop environment, or many other issues.
I had this problem because the default shell had been changed to zsh.
I echoed the shell name with echo $SHELL to see this (thanks How to get default shell).
Then I changed it back to /bin/bash with this command: chsh -s /bin/bash (thanks https://apple.stackexchange.com/a/100476/176809).
Create a bash script with the content;
echo "source ~/.bash_profile" >> .profile
Then in Intellij go to preferences/tools/Startup Tasks;
create a run configuration that runs your bash script and you're good to go.
I just restarted my MAC and it picked up the new stuff.
For me at least, the only thing that works was to put this in the Shell path variable inside of Tools > Terminal :
/bin/bash --rcfile ~/.bashrc

Creating aliases in .bash_profile that run a shell script

So I have a script called spotlyrics.sh that I want to be able to run using the command "lyrics" in the terminal.
I have opened up my .bash_profile and am wondering how I can create the alis which 1) finds the script and then 2) executes it
The file is inside a folder called bash at the following path
/Users/username/Documents/bash
What I have so far (inside my bash profile), which doesn't work because I guess it's not "executing" the script.
alias spotlyrics=“/Users/username/Documents/bash/spotlyrics.sh“
I get the following error when running "spotlyrics" in the terminal:
-bash: “/Users/username/Documents/bash/spotlyrics.sh“: No such file or directory
Would love some help, thanks!
You've been editing your .bash_profile with something that is not a proper text editor. The quotation marks are not ASCII, and therefore not actually quotation marks as far as the shell is concerned.
Instead of beating around the bush with aliasing a script to a name it mostly already has, why not put the script in a directory in PATH and let it be its own command?
mkdir ~/bin
echo 'PATH+=:$HOME/bin' >> ~/.bashrc
mv "/path/to/spotlyrics.sh" ~/bin/spotlyrics && chmod +x ~/bin/spotlyrics
Then restart the shell (log out and back in) and you won't need the alias.
Well, the shell scripts are not executable by just calling it's name, they should be run using "source" command(in case of not c-shell, dot command(.) can also be used).So while adding an alias in .bashrc or .bash_profile for running a shell script append source command before the path to the shell script.
In your case probably this should work:`
alias spotlyrics='source /Users/username/Documents/bash/spotlyrics.sh'`
Please let me know if it doesn't work. Because it worked for me.

Cygwin shell doesn't execute .bashrc

After start the cygwin shell, it just locate in a wrong home dir:
xfire#codingme.com ~
$ pwd
/cygdrive/c/Users/xfire
But it used to be /home/xfire
xfire#codingme.com /etc
$ cat passwd | grep xfire
xfire:unused:22773:10513:U-CORP\xfire,S-1-5-21-527237240-725345543-682003330-12773:/home/xfire:/bin/bash
And the .bashrc in the /home/xfire was not executed, even I copy it to the /cygdrive/c/Users/xfire, it also doesn't work!
On cygwin, I add this to my ~/.bash_profile:
. ~/.bashrc
Some program add an "HOME" environment in windows registry and set the value to "C:\Users\xfire", that's why cygwin take that directory as the home. cygwin.com/faq-nochunks.html
On my version of cygwin I found that only ~/.profile was being execueted so added
if [ -e "${HOME}/.bash_profile" ]; then
source "${HOME}/.bash_profile"
fi
to the .profile file. My .bash_profile file contains another test for .bashrc and executes that from inside there. I also added the following two lines to my .bashrc file.
export BASH_ENV="${HOME}/.profile"
export ENV="${HOME}/.profile"
The first of these ensures that .profile gets executed in non-interactive terminals and the second ensures it gets executed in POSIX terminals. I found a very useful explanation of what get run and when in the Bash Reference Manual.
In your case it wouldn't help as you have an issue with the value of your HOME environment variable but this page comes up quite high on the list when searching for this issue.
You can also also set BASH_ENV variable, e.g., BASH_ENV='C:\DOCUME~1\dwyttenb\.bashrc'
~/.bash_profile is executed before the initial command prompt is returned to the user. After that, every time a new shell is opened, ~/.bashrc is executed.
Adding . ~/.bashrc at end of ~/.bash_profile has resolved the problem.
Now you can check existing aliases using alias command.
Find more details on github.

bash shell $HOME assignment and script execution

I've just begun learning Unix and have so far encountered two elementary though difficult to resolve problems:
When I set HOME='' in a shell script to a designated directory, the current directory no longer seems to be recognized. That is, 'cd ~/' spits out the message: 'no such file or directory' message. Although, curiously enough, if aliases assignments are made within the script, a source call seems to activated them nonetheless. How come?
Ex:
$ more .profile
HOME="~/Documents/Basics/Unix/Unix_and_Perl_course"
cd $HOME
[...]
$ source .profile
-bash: cd: ~/Documents/Basics/Unix/Unix_and_Perl_course: No such file or directory
When I created a simple shell script via nano ('hello.sh'), I can't seem to execute it simply by typing 'hello.sh' in the terminal. This issue fails to resolve even after I 'chmod +x' the file. What's the problem?
Ex:
$ more hello.sh
# my first Unix shell script
echo "Hello World"
$ hello.sh
bash: hello.sh: command not found
Thanks!
You also don't want to 'overload' $HOME, the default location for HOME is always your home directory. If you goof with that, lots of things will break.
As far as hello.sh - thats because you don't have '.' in your $PATH. (Which is a good thing)
Try:
./hello.sh
If it says it can't execute
chmod 755 hello.sh
./hello.sh
~ = $HOME
. (pwd) is not in $PATH

Resources