Ben Chuanlong Du's Blog

And let it direct your passion with reason.

The Right Way to Export PATH in Shell

Some people suggest exporting PATH only in .bash_profile instead of in .bashrc (for Bash). The helps but does not resolve the issue of possible duplicated paths in $PATH. The right way is to check for existence of the path in the $PATH environment variable first, and add it only when …

Docker in WSL 2

Tips and Traps

  1. Docker on WSL 2 works great. However, the performance of IO is extremely bad if it access the Windows filesystem. For more discussions, please refer to WSL 2 Filesystem .

  2. Docker containers launched from a WSL (e.g., Ubuntu) shell will continue to run after the WSL shell …

Change Shell in Mac

You can check the current shell in use by running the following command.

echo $SHELL

However, notice that echo $SHELL does not report the right shell sometimes. A more robust way is to use echo $0.

The default shell can be changed using thee comamnd chsh. For example, thee following …

Regular Expression in Bash

It is suggested that you use Python script instead of Shell script as much as possible. If you do have to stick with Shell script, you can use =~ for regular expression matching in Bash. This make Bash syntax extremely flexible and powerful. For example, you can match multiple strings using …

Using Bash in Docker

If the docker container was started using /bin/bash (you can check using docker ps) command you can access it using attach.

docker attach container_name_or_id

If the docker container was started but not with /bin/bash, you have to create a bash instance inside the container using exec.

docker exec …