Alias stops working after adding another one [duplicate] - bash

This question already has answers here:
Are shell scripts sensitive to encoding and line endings?
(14 answers)
Closed 2 years ago.
I am using WSL2 Ubuntu with Windows. I have an alias opening Notepad++ on Windows defined inside WSL like this:
alias npp="/mnt/c/Program\ Files/Notepad++/notepad++.exe"
and it works... but as soon as I add another alias, e.g.
alias npp="/mnt/c/Program\ Files/Notepad++/notepad++.exe"
alias l="ls -l"
I get the error - : No such file or directory/Notepad++/notepad++.exe. It works only when it is the last alias defined in the file.
My guess is it might have something to do with a space in the Notepad++ path but I am not really sure anymore. I tried different ways of escaping with no luck. What is happening here, what's the cause and the fix?

I can reproduce if I edit a script with those aliases using Notepad++ and leave the line endings as "Windows". If you want to use Notepad++ to edit your bash scripts, make sure to use Edit -> EOL Conversion -> Unix (LF) before saving.
After doing that, the alias script works correctly for me.

Related

If I put a bunch of curl commands into a .sh file, and run it, will it run those commands? [duplicate]

This question already has answers here:
Run text file as commands in Bash
(5 answers)
Closed 4 years ago.
Sorry, seems like a stupid question but I cannot find an answer (and am not on mac to test)!
In Windows, I open notepad and copy/paste in a bunch of curl commands, save as a .bat and click on it. Then it runs, easy peasy.
In Mac, will I get the same behaviour if I save the file as .sh? Do I need to install anything from terminal?
Sure, and you don't even need the .sh extension although its handy to help you recognize scripts. Just open a text file in your favorite editor. Type in the curl commands you want to run and save the file. There are two ways to run the file from the bash shell. you can
source filename
Or type:
chmod +x filename
to make the file executable and then type
./filename
to run it.

Alias not working in Ubuntu 14.04 [duplicate]

This question already has answers here:
How to set an alias inside a bash shell script so that is it visible from the outside? [duplicate]
(4 answers)
How to reload .bashrc settings without logging out and back in again?
(18 answers)
Closed 6 years ago.
So I have added an alias for jumping to another directory like this
in my ./bashrc file , Looks like this
alias crmx="cd /var/www/crm/website-crm/"
Then i saved the file
but when I try to run
crmx
it says
command not found
Also I tried to do alias to see all the command but my command is not listed
Any idea ?
The file is ~/.bashrc (starting with a dot).
And you have to source it (reload) by doing source ~/.bashrc or just by closing and reopening your terminal.
You can also type ps to check if your shell is bash (for example if it's zsh you have put your alias in the ~/.zshrc file)
Let's suppose you are on bash.
Once you saved that file, you have to have bash read it with a command like this:
. ~/myaliasfile
or like this
source ~/myaliasfile
if the file resides in your home directory. Specify the path (relative to your home or absolute) otherwise.
Then you'd go to your .bashrc file and add the very same line to the end of it. By doing so the alias(es) will be read and made available to every single bash invocation and login.
Done!
More details here and here.

Mac Yosemite, tried to change my bash profile path, but I messed up and now terminal cant find any commands [duplicate]

This question already has an answer here:
How to restore .bash_profile on a mac? None of my unix terminal are working [closed]
(1 answer)
Closed 7 years ago.
I tried fixing an unrelated problem by changing my path in my .bash_profile, but I think I messed up and now my terminal cant find any command, not even 'ls' or 'nano'. Is there any way to edit the bash profile file back to the original without using the command line? Is there a way I could find my bash profile in finder and edit it with the text app? Or do I have to factory wipe my MacBook?
okay yeah I fixed it by changing my setting PATH=/usr/local/bin:/usr/local/sbin:/usr/local/mysql/bin:/usr/bin:/bin:/usr/sbin‌​:/sbin and that gave me the bash commands back and then I could use nano to edit the profile back to how it was before I messed with it. I feel really dumb.

Bash error after opening Terminal and running shell scripts (CentOS) [duplicate]

This question already has answers here:
Error message on Terminal launch [duplicate]
(2 answers)
Closed 6 years ago.
Every time I open Terminal in CentOS 6.4, I get the error:
bash: usr/local/bin: No such file or directory
I've checked .bashrc and .bash_profile to see if there are any lines that reference usr/local/bin, but haven't found anything. The same error also appears when I switch to root, or run a shell script.
Is it as simple as adding a backslash in front of usr? Like so--
/usr/local/bin
Still don't know where the error is happening though. Any help is much appreciated. Thanks!
This is strange as the normal bash directory on a centos 6.4 system is /bin/bash, however I would advise you to check the following:
echo $SHELL
It should pull your SHELL environment variable to show you where what shell you are using, normally it looks like this:
SHELL=/bin/bash
If it's different say for example:
SHELL=usr/local/bin/bash
then I would check your passwd file to make sure your users default shell is pointing to the right place.
username:x:601:601::/home/username:/bin/bash
Also I would suggest check where you shell actually lives
which bash
/bin/bash
And make sure everything is pointing to the correct location.

vim - run :!commands in my .bashrc [duplicate]

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
Commands executed from vim are not recognizing bash command aliases
Why doesn't my vim know my alias?
say I set
alias kapow='grep'
in my .bashrc, which I source after.
I open vim, type
:!kapow "dude"
but vim tries to run /bin/bash kapow, when I actually wanted it to run my alias.
How does one run commands from a bashrc inside of vim (without leaving to the :shell)?
The vim manual says this about :!
On Unix the command normally runs in a non-interactive shell. If you want an interactive shell to be used (to use aliases) set 'shellcmdflag' to "-ic".

Resources