DALLASCAO.COM

Site of Cao Shouguang, English to Chinese translator

split string in Bash

split string in Bash
emails="[email protected];[email protected];[email protected]" emails=${emails//;/ } #replace ; with space arr_emails=($emails) # put them into an array for item in ${arr_emails[@]}; do echo $item done In fact this works also. You don’t really need arrays emails="[email protected];[email protected];[email protected]" emails=${emails//;/ } #replace ; with space for item in $emails; do echo $item done But with using arrays, you can do many […]Read More

sed regular expressions

sed regular expressions
echo 'iweigh297lbs' | sed 's/.*[^0-9]\([0-9]\+\).*/\1/' The expression has to match the whole line. Greed: The expression will match the largest possible from left to right. This won’t work. echo 'iweigh297lbs' | sed 's/.*\([0-9]\+\).*/\1/' Output 7 This won’t work echo 'iweigh297lbs' | sed 's/.*[^0-9]\([0-9]*\).*/\1/' This works echo 'iweigh297lbs' | sed 's/.*[^0-9]\([0-9][0-9]*\).*/\1/' + has to be escaped. […]Read More

How to run chrome from command line

How to run chrome from command line
YOu need first add the chrome.exe directory to windows environment. [Environment]::SetEnvironmentVariable("Path", "$env:Path;C:\Program Files (x86)\Google\Chrome\Application", "User")Read More

sudo: allow non-root users run certain commands

sudo: allow non-root users run certain commands
Allow user www-data to run ps www-data ALL = NOPASSWD: /bin/psRead More

Script works under command line but not in crontab?

Script works under command line but not in crontab?
Add the following lines to crontab and then it will work: SHELL=/bin/bash PATH=/usr/lib/lightdm/lightdm:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/gamesRead More