-bash: ls: command not found on macOS Big Sur 11.0.1 - bash

Did I touch something wrong on the terminal?
I'll tell you the details.
git clone https://github.com/rbenv/rbenv.git ~/.rbenv
cd ~/.rbenv && src/configure && make -C src
export PATH="$HOME/.rbenv/shims:~/.rbenv/bin"
And from here, the 'ls' didn't work in Bash.
Can I know the solution to the problem?
Please! I'm panicking.
I entered the command below because I was embarrassed, but I hope it will be a reference...
cd sws
cd ..
ls
cd ..
ls
cd ..
pwd
ls
pwd
cd home
ls
pwd
cd sws
cd user
ls
ls -al
cd ..
pwd
cd ..
ls
pwd
cd ~/.rbenv && src/configure && make -C src
ls
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bash_profile
ls
echo 'export PATH="$HOME/.rbenv/bin:~/.rbenv/bin"' >> ~/.bash_profile
ls
What I've been following:
https://ernestojeh.com/fix-jekyll-on-macos-big-sur
https://github.com/rbenv/rbenv#basic-github-checkout

Related

chmod +x cant find build.sh file

I have been trying to make a VCS in C++ but the build file is not running in my LINUX(Ubuntu).
It is prompting the above message.
my build file is as follows:
#!/bin/bash
sudo apt-get update
udo apt-get install openssl -y
sudo apt-get install libssl-dev -y
mkdir -p ~/imperium/bin
cp imperium.sh ~/imperium
cd ..
make
cd ~/imperium/bin || echo "error"
chmod +x main
cd ..
if grep -q "source $PWD/imperium.sh" "$PWD/../.bashrc" ; then
echo 'already installed bash source';
else
echo "source $PWD/imperium.sh" >> ~/.bashrc;
fi
my imperium.sh file is also as follows:
function imperium(){
DIR=$PWD
export dir=$DIR
cd ~/imperium/bin || echo "Error"
./main "$#"
cd "$DIR" || echo "Error"
}
I will be heavily obliged if any one can solve this problem of mine. After chmod I have been doing:
./build.sh but its prompting that build.sh file does not exists.
For me it seems you have a typo right in the 3rd row "udo" ->
"sudo".
Also, You should avoid using cd .. and use relative paths for
the commands.

Messed up terminal after installing Angular [altered my zsh $PATH?]

I just installed Angular and after the default installation (as set out here: https://angular.io/guide/setup-local). After running the standard commands my terminal would not recognise ng (so I could not use ng new my-app).
To solve this problem I did the following based on a stackoverflow answer:
echo -e "export PATH=$(npm prefix -g)/bin:$PATH" >> ~/.bashrc
source ~/.bashrc
ng --version
(I had no knowledge of what PATH was when doing this, or what the command I was running did...)
This worked, and my ng --version returned a result and I was able to build and run an Angular app.
However when I opened a new tab in my terminal all my normal terminal 'styles' (I use zsh) had gone.
My friend and I tried to resolve the problem, which he felt might be related to my terminal settings (his 'Command (complete path)' read: /usr/local/bin/zsh, and mine was /bin/zsh). So we tried a few things but none have worked and it might be worse - this included resetting my $PATH based on another stackoverflow answer to /usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/Apple/usr/bin:/Library/Apple/bin.
We also switched back and forth from /bin/zsh to /bin/bash to try and resolve things, but this did not do anything.
The current state of things is that I cannot run rails commands where I normally could (for example), also things like ll (which returns zsh: command not found: ll).
This is my .zsh_history file:
which zsh
which bash
cd code
cd
ls
lsa
ls -a
cat .aliases
vi .aliases
sudo v
sudo vi .aliases
npm install -g angular
npm list
npm install -g #angular/cli
cd code
ls
cd JoshInLisbon
cd ..
JoshInLisbon
ls
mkdir Angular
mkdir Rails
cd rails
ls
cd ..
open
open .
cd WALD
ls
ll
lll
ls -a
cat .git
.git
ls
ls -a
cd ..
..
JoshInLisbon
..
JoshInLisbon
ls
cd Angular\ Projects
ng new my-first-app
which ng
which angula
which angular
echo $path
npm -v
which node
node -v
npm install -g #angular/cli
ng --version
brew install node
node -v
brew postinstall node
sudo npm cache clean -f
sudo npm install -g n
sudo n stable
npm install -g n
sudo npm install -g n
sudo n stable
brew doctor
npm -v
which brew
which npm
brew -v
brew update
npm -v
npm install npm
npm -v
npm install -g npm
npm install -g #angular/cli
ng --version
npm ls --global --depth 0
npm install -g #angular/cli#latest
echo -e "export PATH=$(npm prefix -g)/bin:$PATH" >> ~/.bashrc
source ~/.bashrc
ng --version
cat ~/.bashrc
echo $PATH
ng new my-app
ls
my-app
npm outdated
..
npm install --save core-js#^3
my-app
npm install --save core-js#^3
npm install --save-dev "jasmine-core#>=3.5"
ng serve --open
exit
ls
cd code
ls
codesign
code
ls
cd code
ls
cd JoshInLisbon
ls
cd an
cd Angular\ Projects
ls
cd my-app
code
ng
code
code --
ls
cd ..
cd taaalk
cd ..
cd taaalk_edge
echo $PROMPT
zsh --version
chsh -s
ls
cd code
ls
cd JoshInLisbon
chsh -s /bin/bash
ls
zsh --version
ls -a
cat .zshrc
cd .zshrc
echo $PATH
echo $PATH
vim
cat
ls -a
vim .zshrc
vim .bash_profile
~/.MacOSX/environment.plist
echo $PATH
plutil -lint ~/.MacOSX/environment.plist
xcode-select --install
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
brew update
sh -c "$(curl -fsSL https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"
ls
ls -a
cat .zshrc.backup
cd code
cd JoshInLisbon
cd Rails\ Projects
rails new thing
rails new thing
echo $PATH
..
ls ..
cd ..
cd ..
cd
ls -a
cat .zshrc.backup
ls -a
cat .zsh_history
vim .bash_profile
ls -a
vim .zcompdump-jmpb-5.7.1
vim zshrc.backup
cat .zshrc
.zsh_history
vim .zshrc
vim .shell.pre-oh-my-zsh
ll
ll -a
I can see my .zshrc file when I do ls -a, however it is empty.
This is my .bash_history
ls
sh -c "$(curl -fsSL https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"
history
which zch
which zsh
echo path
echo $PATH
cd code
cd JoshInLisbon/
rails new project
export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
echo $PAtH
echo $PATH
rails new
npm -version
which zsh
cd ..
cd ~
ls
ls -a
cat .szhrc
cat .zshrc
cat .zshrc
ls -a
cat .bash_profile
echo $PATH
cat .zsh_history
cat .bashrc
export PATH=/Users/joshua/.npm-global/bin:./bin:./node_modules/.bin:/Users/joshua/.rbenv/shims:/Users/joshua/.rbenv/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/Apple/usr/bin:/Library/Apple/bin:/usr/local/sbin
echo $PATH
which ruby
which zsh
cd code/
cd JoshInLisbon/
cd Rails\ Projects/
rails new thing
ls
rm -R thing
ls
which brew
which zsh
cd ..
cd
ls
ls -a
cat .zshrc
cat .zshrc
cat .bash_profile
cat .oh-my-zsh/
cd .oh-my-zsh/
ls
cat .oh-my-zsh.sh
cd
ls
ls -a
cat .zshrc.backup
echo $ZSH
export ZSH="/Users/joshua/.oh-my-zsh"
echo $ZSH
which rails
ll
This might be my old path? export PATH=/Users/joshua/.npm-global/bin:./bin:./node_modules/.bin:/Users/joshua/.rbenv/shims:/Users/joshua/.rbenv/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/Apple/usr/bin:/Library/Apple/bin:/usr/local/sbin
Anyway, you are a hero if you made it this far and if you have any idea what I should do I would be very grateful.
This was resolved by moving my dotfiles (which contains all my zsh settings) back to the original location. The change was caused by the re-ordering of many folders.
I also restored my PATH back to the old one pasted at the bottom of the question.

Linux symbolic links how to make target file in currently directory an automatic absolute path?

Here is the story:
cd ~
mkdir bin
export PATH=$PATH:bin
mkdir -p projects
cd projects
echo 'hello world' > hello.sh
chmod +x hello.sh
ln -s hello.sh ~/bin/hello
hello
output:
-bash: hello: command not found
How I changed it:
ln -s hello.sh ~/bin
hello.sh
The output is more weird:
-bash: /home/qht/bin/hello.sh: Too many levels of symbolic links
I ls it to see what happened:
ls -l ~/bin/hello.sh
/home/qht/bin/hello.sh -> hello.sh
I figure it out, hello.sh reference itself. And hello before reference hello.sh which doesn't exist.
I fix it by:
ln -sf $PWD/hello.sh ~/bin/hello
ls ~/bin/hello
/home/qht/bin/hello -> /home/qht/projects/hello.sh
and it works, I also man ln to see if there is a convenient option to do that, this is what I found:
ln -sfr hello.sh ~/bin/hello
ls -l ~/bin/hello
/home/qht/bin/hello -> ../projects/hello.sh
And it works, the -r option did the work.
But I'm curious, if ln -r can automatically write the relative path data into symbolic links, Why doesn't there an option maybe -a to do the absolute path work.
Or, is relative path for links is more practical than absolute path?
Try this:
cd ~
mkdir bin
export PATH=$PATH:~/bin # Need absolute path to bin
mkdir -p projects
cd projects
echo 'echo "hello world"' > hello.sh # If the script is just hello world
# this will become an infinite loop
chmod +x hello.sh
ln -s "$PWD/hello.sh" ~/bin/hello # the symbolic link in this case
# needs to be a absolute path
hello

How to find out the path that will be used in `cd -`?

I know that it is possible to use cd - to switch between 2 paths:
user#server:~$ cd a
user#server:~/a$ cd ~/b
user#server:~/b$ cd -
/home/user/a
user#server:~/a$ cd -
/home/user/b
user#server:~/b$
I want to use this feature to do something with the previous path. Maybe there is some variable that points to the previous path so I can do thins like:
user#server:~/a$ cd ~/b
user#server:~/a$ ls -d $PREVIOUS_PATH
/home/user/a
user#server:~/a$ cp file $PREVIOUS_PATH # will copy file to /home/user/a
user#server:~/b$ cd -
Old working directory is stored in OLDPWD environment variable. This variable is updated every time we change directory. This also means that it is not set when we launch terminal.
user#server:~/a$ cd ~/b
user#server:~/a$ ls -d "$OLDPWD"
/home/user/a
user#server:~/a$ cp file "$OLDPWD" # will copy file to /home/user/a, ""
user#server:~/b$ cd -

basic BASH variable call failing in script

Why is this basic variable call in my script failing?
The script is just below and the errors outputted in terminal after execution are below the script.
Line 8 is the first sudo command.
I am executing this script as root in terminal for now. It works just fine if I execute the commands manually, one-at-a-time, within terminal...
I would be grateful for any insight.
#!/bin/bash
echo Enter username
read NAME
echo Enter number
read NUM
sudo (cd /Users/$NAME && tar c .) | (cd /Users/$NUM && tar xf -)
sudo chown -R $NUM:"Domain Users" /Users/$NUM
sudo chmod g+rwx /Users/$NUM
Stephen-Kucker:Desktop root# ./stackoverflowq.txt
Enter username
jsteinberg-c
Enter number
admin
./stackoverflowq.txt: line 8: syntax error near unexpected token `cd'
./stackoverflowq.txt: line 8: `sudo (cd /Users/$NAME && tar c .) | (cd /Users/$NUM && tar xf -)'
Try this:
sudo tar -C /Users/$NAME -c . | sudo tar -C /Users/$NUM -xf -
You need to use the -s option to pass an arbitrary shell command (like the pipeline shown) to the shell with sudo:
sudo -s "(cd /Users/$NAME && tar c .) | (cd /Users/$NUM && tar xf -)"

Resources