scp gives "[file] not a directory" error when using parameters - bash

I created a custom command in my .bashrc file which is:
function copySomething{
scp "$1" somesshalias:~/
}
Whenevery I type copySomething filename.txt it gives me filename.txt: Not a directory. However: When I type scp filename.txt somesshalias:~/ it works as expected.
What am I doing wrong?
EDIT:
.bashrc is sourced
removing the target file doesnt change anything
Solved!
I sourced the bashrc after every change but it seems like the old function did not get replaced by the new one. Restarting my console fixed the problem. Should have done that earlier...

Sourcing was the problem.
I sourced the bashrc after every change but it seems like the old function did not get replaced by the new one. Restarting my console fixed the problem. Should have done that earlier...

Related

source /.bash_profile command not working

I am trying to refresh my aliases on my Mac (OS Catalina 10.15.6) after defining new aliases in my .bash_profile file with the command:
source ~/.bash_profile
But terminal keeps giving this error message:-bash: s: command not found
This is confusing because for the longest time this command worked. I even had it included in my .bash_profile file as an alias, where it worked fine.
I'm aware the problem could have to do it with an error in my PATH but I've never made any edits to my PATH so have no idea what the issue could be?
Thanks in advance.
My first instinct would be to check both ~/.bashrc, and /etc/bashrc if it exists. That is where I customarily define aliases, and it looks to me as though a bad alias may be your problem.
I'm not saying it was the one you made, although it might be. Just go through your rc and profile files and look for any aliases which might in any way clash with source.
I suspect the source command is working just fine and the problem is a bad line in the ~/.bash_profile itself that looks like it's trying to run a command named s. I would look in there for the problem.
It might help to run it with xtrace on via bash -x ~/.bash_profile – running it in a separate process like that won't have any of the presumably-desired side effects of sourceing it in your current shell, but you can see what it's trying to do so that you can fix it.
(You can also just set -x before the source and get both xtrace and running in the current shell; just be sure to set +x afterwards or your shell session will be full of debug output.)

zsh: command not found - only works when I change path, but on restarting terminal, path changes back

I have 4 files in my bin. Funnily, two of them work when I call them in the terminal - the other (newer) two don't.
My bin file looks like this: https://ibb.co/bsj00jG
When I type 'which chd-project' in terminal (chd-project is one of the bash scripts which works), it says /usr/local/bin/chd-project - however I can't find a local file on my Mac.
When I type which id-project (the bash script that can't be found), it just says id-project not found.
If I set PATH=$HOME/bin, I can then call the id-project file. However, whenever I restart my terminal, it resets again. This can sometimes be buggy, though, as later commands in that same bash script can sometimes not be found.
When I type echo $PATH I get /usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
However, like previously stated, I can call chd-project in my terminal (although it says usr/local/bin if i use 'which') but I can't call id-project.
Any help would be greatly appreciated.
Thanks
Your PATH variable is "reset" for every session you start. That's because the current session doesn't set environmental variables persistently. However, before a session is started it executes files that, for example, hold the value of PATH.
If you want to add this for every terminal you open, you should extend your path in your bash profile.
$ echo "export PATH=$PATH:$HOME/bin" >> $HOME/.bashrc
Please take not that you shouldn't overwrite your PATH variable, because it's used to find commands like mv, cp, etc.
EDIT:
I don't know Atom that well, but if you would open a regular (not an in-IDE) terminal it should work. It could be that Atom doesn't execute .bashrc for whatsoever reason. You could try to add it to to your profile.
$ echo "export PATH=$PATH:$HOME/bin" >> $HOME/.profile

`open` Command not found - Oh-My-Zsh

I am trying to open the current directory in the finder using the open . command but nothing happens.
Not even an error.
What could be the problem?
Typically, if a command does not work while the rest is working, it means it is overwritten somehow:
alias
bash function
The OP relidon confirms in the comments:
I had created by own bash function and called it open

Function defined in .bashrc not recognized

I'm trying to make the function below available from a bash session, so I added it to .bashrc:
function del () { mkdir -p ~/.trash; mv "$#" ~/.trash; }
This works fine in a shell script, but when I call the .bashrc version from the terminal, like:
$ del test.txt
I always get this:
bash: syntax error near unexpected token `test.txt'
I am executing source ~/.bashrc every time I change the file, and I already tried different ways of writing the function, what's wrong with it? It works in a .sh file, so maybe a special syntax for .bashrc is required?
EDIT
Turns out that the session kept an old alias with the same name, even after sourcing .bashrc again. type del helped me detecting it. Running unalias del or starting a new session solved the problem.
From the OP's ammended closing paragraph:
Turns out that the session kept an old alias with the same name, even
after sourcing .bashrc again. Type del helped me detecting it. Running
unalias del or starting a new session solved the problem.
(This answer exists only to keep this Q out of the unanswered category.)

Accidentally wiped out PATH definition in Bash shell

I created a.bash_profile and defined
export PATH=/user/local/bin
rather than
export PATH=/user/local/bin:$PATH
Then, I ran
source ~/.bash_profile
Now none of the command, e.g., ls works. Is there a way to back out this change? Thank you.
If you have fixed your .bash_profile file, you just restart bash to get your $PATH back. If that's not an option, or you can't fix the file externally, you can do export PATH="/bin:/usr/bin:/usr/local/bin", which should give you enough to get to vi or some other text editor so you can fix your .bash_profile, then you can restart bash.

Resources