linux - Using the passwd command from within a shell script

from "man 1 passwd": --stdin This option is used to indicate that passwd should read the new password from standard input, which can be a pipe. So in your case adduser "$1" echo "... Read More

linux - How to get the name of the current git branch into a variable in a shell script?

The * is expanded, what you can do is use sed instead of grep and get the name of the branch immediately: branch=$(git branch | sed -n -e 's/^\* \(.*\)/\1/p') And a version using git symbolic-ref, as... Read More

shell - How can I repeat a character in Bash?

You can use: printf '=%.0s' {1..100} How this works: Bash expands {1..100} so the command becomes: printf '=%.0s' 1 2 3 4 ... 100 I've set printf's format to =%.0s which means that it will always p... Read More

shell - Continuously read from STDOUT of external process in Ruby

I've had some success in solving this problem of mine. Here are the details, with some explanations, in case anyone having a similar problem finds this page. But if you don't care for details, here's... Read More

How can I open a Shell inside a Vim Window?

Neovim and Vim 8.2 support this natively via the :ter[minal] command. See terminal-window in the docs for details.... Read More

linux - rsync copy over only certain types of files using include option

I think --include is used to include a subset of files that are otherwise excluded by --exclude, rather than including only those files. In other words: you have to think about include meaning don't... Read More

shell - Comparing numbers in Bash

In bash, you should do your check in arithmetic context: if (( a > b )); then ... fi For POSIX shells that don't support (()), you can use -lt and -gt. if [ "$a" -gt "$b" ]; then ... fi You... Read More

bash - Can colorized output be captured via shell redirect?

One way to capture colorized output is with the script command. Running script will start a bash session where all of the raw output is captured to a file (named typescript by default).... Read More

shell - What does "&" at the end of a linux command mean?

The & makes the command run in the background. From man bash: If a command is terminated by the control operator & , the shell executes the command in the background in a subshell. The shell does no... Read More

shell - How to create a cron job using Bash automatically without the interactive editor?

You can add to the crontab as follows: #write out current crontab crontab -l > mycron #echo new cron into cron file echo "00 09 * * 1-5 echo hello" >> mycron #install new cron file crontab mycron rm... Read More