A cross-platform shell.
Double quotes always recommended for cross-platform compatibility.
See my new-machine repo for installation and my recommended .bashrc file.
This How-To Geek article on the difference between terminal, shell, and console also covers TTY (teletypewriter).
- Bash reference manual
- "[Bash] is intended to be a conformant implementation of the IEEE POSIX Shell and Tools portion of the IEEE POSIX specification (IEEE Standard 1003.1)."
--posixaligns more closely with POSIX. However, I don't use this flag.- "For almost every purpose, shell functions are preferable to aliases."
I don't use Windows enough to try to generalize my AI-generated "create symlink" script there, so just copy paste that file where you need it!
Note that this .bashrc file is specific to Linux Mint and may not behave well on other operating systems.
chmod +x ./link-bashrc.sh./link-bashrc.shsource ./.bashrc# Print "Hello world, x is 2" to stdout (excluding quotes)
# No spaces allowed between var name, `=`, and var value
x=2
# Spaces allowed within quoted strings.
# Quotes are not part of var value.
y="Hello world"
echo $y, x is $x# Open the .bashrc file in VS Code
alias bashedit='code ~/.bashrc'However, functions are preferable to aliases according to the reference manual.
This function uses jq to edit JSON files, editing the local package.json by default:
json_edit() {
if [ $# -eq 0 ]; then
echo "Usage: json_edit 'jq_filter' [file]"
echo "Examples:"
echo " json_edit '.author = \"Mark Wiemer\"'"
echo " json_edit '.scripts.build = \"tsc\"'"
echo " json_edit 'del(.devDependencies.eslint)'"
return 1
fi
local filter="$1"
local file="${2:-package.json}"
jq "$filter" "$file" > temp.json && mv temp.json "$file"
echo "Applied filter: $filter"
}These functions create or reset the package.json file, with some customizations just for me:
new_project() {
pnpm init
pnpm add -D sort-package-json
json_edit '.author="Mark Wiemer"'
json_edit '.scripts."validate:fix"="sort-package-json"'
local dir_name=$(basename "$PWD")
json_edit ".name=\"@mark-wiemer/$dir_name\""
pnpm run validate:fix
}
reset_project() {
rm package.json
new_project
}