zsh command not found issue - zsh

I installed sublime text 2 and created a symlink to it and placed it in ~/bin. I added ~/bin to PATH variable in ~/.zshrc.
If I try to execute subl (sublime's symlink), I get:
zsh: command not found: subl
But if I execute ~/bin/subl, it works correctly.
Echoing the PATH shows that ~/bin is in the PATH variable.:
~/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
Any idea what can cause the command not found issue?

bash interprets ~ in PATH, but most shells do not.
Use $HOME instead.

Related

Run jq command in git-bash

jq command not found after adding jq executable
installing jq on git bash
My usecase is more similar with above shared references. I tried to execute a hook that needs to parse a json file. When hook gets executed it throws bash: jq:command not found error. So. I downloaded jq-win64.exe file and copied it to /usr/bin in Git folder. Then from git-bash I run export PATH=$PATH:"/C/Program Files/Git/usr/bin/jq-win64.exe" command and there is no error but when I checked jq --version command it still shows bash: jq:command not found error
Am I missing something? I even tried in windows cmd but is of no use. Hope someone can help me.
Thanks in advance!!!
PATH contains directories. That means what you should do:
Rename jq-win64.exe to jq.exe or just jq. (e.g. cp ~/Downloads/jq-win64.exe /usr/bin/jq).
You don't have to export your path, /usr/bin is already part of it.
If you didn't rename the file to jq (or jq.exe), then you would have to run it as jq-win64 in your console.
You could also put the binary into ~/bin folder, which should be part of PATH too. If it isn't, you can add it. Then you don't need to mess with your global binaries folder.

Error while making symbolic links for nvim

So I was making a symbolic links for nvim so that if i use vim command it opens nvim.
So I used this code
ln -s (which nvim) /usr/local/bin/vim
but when i ran the command it showed this error
zsh: unknown file attribute: h
so plz tell me my mistake and solution for that
You need to put the path to nvim as the first parameter, i.e.
ln -s =nvim /usr/local/bin/vim
In general, =foo expands to the absolute path of the command foo (by using PATH search).

Executing an executable must be done using a path. Why?

In the following:
Roberts-MacBook-Pro:Code robertnash$ mkdir Flag
Roberts-MacBook-Pro:Code robertnash$ cd Flag/
Roberts-MacBook-Pro:Flag robertnash$ swift package init --type executable
Roberts-MacBook-Pro:Flag robertnash$ swift build
Compile Swift Module 'Flag' (1 sources)
Linking ./.build/debug/Flag
In order to execute the executable, it must be a path, like so
Roberts-MacBook-Pro:Flag robertnash$ .build/debug/Flag
Hello, world!
If I go to where 'Flag' is located, the command cannot be run by simply typing 'Flag'.
Roberts-MacBook-Pro:Flag robertnash$ cd .build
Roberts-MacBook-Pro:.build robertnash$ cd debug
Roberts-MacBook-Pro:debug robertnash$ Flag
-bash: Flag: command not found
It must be a path, like so.
Roberts-MacBook-Pro:debug robertnash$ ./Flag
Why is that ?
If you run export PATH="$PATH:." then it will add the current working directory to your path and you won't need the ./ prefix. (Most (all?) shells accept just a trailing colon without the dot, but I find it's more explicit about what it does.)
This isn't present by default because it is a security risk: a malicious script could be named as something missing from your path, like nmap or even as a typo like sl, and placed in a directory in the hopes that you run it. Forcing you to prefix ./ is a good way of avoiding that.

Trying to set up sublime text 2 to open files in unix terminal but getting an error

I'm trying to set up sublime text 2 to open a file in my cygwin terminal by using the command 'subl [file]'. I run the below command in my terminal as instructed in a number of sites
ln -s "/Applications/Sublime Text 2.app/Contents/SharedSupport/bin/subl" /bin/subl
However, I get this error:
ln: failed to create symbolic link `/bin/subl': File exists
How do I work around that?
Perhaps you could try using 'alias', instead?
Add a line to your .bashrc file similar to:
alias subl='/cygdrive/c/Applications/Sublime\ Text\ 2.app/Contents/SharedSupport/bin/subl'
Then do a 'source .bashrc' command to load the new alias.
Try this on a Mac:
sudo ln -s /Applications/Sublime\ Text\ 2.app/Contents/SharedSupport/bin/subl /bin/subl
You're on Windows, right? That directory you're trying to point to is the directory for the Mac OS install of Sublime Text 2. You'll probably want something more like this, though adjust the path to sublime_text.exe to match where yours is:
ln -s /cygdrive/c/Program\ Files/Sublime\ Text\ 2/sublime_text.exe /usr/local/bin/subl
Make sure /usr/local/bin is some directory in your PATH (echo $PATH to find out) so that your subl command will work from anywhere. Then you will be able to do subl . from any project directory to open that project in Sublime.

shebang line not working in R script

I have the following script
#!/usr/bin/Rscript
print ("shebang works")
in a file called shebang.r. When I run it from command line using Rscript it works
$ Rscript shebang.r
but when I run it from the command line alone
$ shebang.r
It doesn't work. shebang.r command not found.
If I type (based on other examples I've seen)
$ ./shebang.r
I get permission denied.
Yes, Rscript is located in /usr/bin directory
Make the file executable.
chmod 755 shebang.r
In addition to Sjoerd's answer... Only the directories listed in the environment variable PATH are inspected for commands to run. You need to type ./shebang.r (as opposed to just shebang.r) if the current directory, known as ., is not in your PATH.
To inspect PATH, type
echo $PATH
To add . to PATH, type
export PATH="$PATH:."
You can add this line to your ~/.bashrc to make it happen automatically if you open a new shell.

Resources