Notepad/enter/Coding Tips (Classical)/Terminal Tips/1. Terminals/Shells/Bash.md

57 lines
2.0 KiB
Markdown
Raw Normal View History

2023-07-05 18:29:11 +00:00
# Bash
Bash is a classic and should always be understood. After all, it was the first shell that you used so there's a bit of nostalgia surrounding it.
- `touch` creates the file named `zk_sync` and `chmod +x` makes the file an executable file, but we still need to say what shell will execute this file, and what exactly are the commands to be executed.
- [ bash command](https://discussions.apple.com/thread/252176464) for Big Sur if you ever decide to upgrade
- the oh-my-zsh version of bash is now regularly maintained through a git repo called [Bash-It](https://github.com/Bash-it/bash-it)
- check the file size of something in your directory by ```wc -c /Users/shwethajayaraj/qisket/file```
- you can further turn it into a bash variable by doing:
- ```myfilesize=$(wc -c "/etc/passwd" | awk '{print $1}')
printf "%d\n" $myfilesize
2023-07-15 02:28:31 +00:00
echo "$myfilesize"```
### Shell Scripting Tips:
- Safe shell scripting practices --> Make sure to use " " !
- example : `cat /Applications/Android Studio.app/Contents` will give you an error
- but `cat "/Applications/Android Studio.app/Contents"` will work!
- Export paths as an Env variable
- example: `export AS_HOME="/Applications/Android Studio.app/Contents"`
- Dealing with Path with Spaces in it:
- use either back slashes or quotation marks not both
- example:
```shell
export PATH=/Applications/Sublime\ Text\ 2.app/Contents/SharedSupport/bin/subl:$PATH
```
or
```shell
export PATH="/Applications/Sublime Text 2.app/Contents/SharedSupport/bin/subl:$PATH"
```
Not both.
Try out the script and see if `the file or directory not found` error comes up.
---
### More Tips:
2023-07-15 02:28:31 +00:00
- a useful [bash history terminal command tweak ](https://danten.io/bash-history-searching-with-inputrc/)
You can just use `exec` to replace your current shell with a new shell:
Switch to `bash`:
```
exec bash
```
Switch to `zsh`:
```
exec zsh
```
This won't affect new terminal windows or anything, but it's convenient.