“Get that Linux feeling - on Windows”
HowTo: Installation steps Mirrors: https://www.cygwin.com/mirrors.html
You must rebuild your application from source if you want it to run on Windows or for Windows applications to take advantage of Cygwin functionality.
Because it provides us a proper Unix shell environment in a Windows world.
There are different shell options on “*nix-systems”:
Among GNU/Linux distros, BASH is currently often the default.
$ mkdir ~/videos
$ cd ~
$ ls
$ cd vid[TAB]
cmd /c c:/ffmpeg/bin/ffmpeg.exe$ ls -la ~/*.* | less
$ ls -la ~/*.* > ~/videos/dirlist.txt
$ cat /etc/services
$ cat /etc/services | grep http
More: Guru99 tutorial - Grep
$ for i in a b c; do echo "$i" > $i.txt; done
$ cp a.txt d.txt
$ md5sum *.txt | tee MD5SUMS.md5
$ cat MD5SUMS.md5 | sort
$ cat MD5SUMS.md5 | cut -d ' ' -f 1
$ cat MD5SUMS.md5 | cut -d ' ' -f 1 | sort | uniq
$ ffprobe -show_streams MYVIDEO.MOV > ~/video/ffprobe.txt
$ cat ~/video/ffprobe.txt | grep "TAG:timecode" | uniq | cut -d '=' -f 2
On unix-like systems, there are 3 basic access rights:
rwx = read, write, execute
In order for a shell script to become executable, set the “x” bit:
$ chmod +x myscript.sh
Every text script must declare its “program loader”:
#!/bin/bash
#!/bin/sh
NAME="$1"
echo "Hello $NAME. :)"
Some similar, some different:
| bat | sh |
|---|---|
| set “NAME=value” | NAME=“value” |
| echo Hello %NAME%! | echo “Hello $NAME!” |
| if “%NAME%”==“” GOTO Label | if [ -z “$NAME” ]; then … fi |
| for %%I in (1 2 3) DO | for $I in 1 2 3; do … done |
| %1 %2 %3 %* | $1 $2 $3 $* |
Batch script:
@echo off
FOR /R "C:\Videos\" %%F IN (*.avi) DO (
echo %%~nF
)
pause
Bash script:
for FILE in ~/videos/*.avi; do
...
done
for ARG in $*; do
echo "Param: $ARG"
done
function MyFunction {
echo "Do stuff here."
echo "My 1st parameter: $1"
local VAR1="whoopie!"
return 1
}
The variable “$?” contains the numeric exit value of the previous execution (of command or function).
# Outputs "1", because source file not found:
$ ffmpeg -i x
$ echo $?
# Outputs "0", because all was okay:
$ ffmpeg -version
$ echo $?Example: Rsync exit values
if [ $EXITSTATUS -ne 0 ]; then
echo "ERROR: Unsuccessful execution ($EXITSTATUS)"
exit 2
fi
# Check if variable matches string:
if [ $NAME == "Dragon" ]; then ...; fi
# Check if variable is empty:
if [ -z $NAME ]; then ...; fi
# Check if parameter is a folder:
if [ -d $SOURCE ]; then ...; fi
# Check if value is greater-than 1:
if [ $VALUE -gt 1 ]; then ...; fi
if [ -z "$NAME ]; then
echo "ERROR: Name is empty"
exit 1
fi
echo "Hello $NAME"
function CheckDir {
local DIR=$1
if [ ! -d "$DIR" ]; then
echo "ERROR: Invalid folder '$DIR'."
return 1
fi
}
${#string} Length of $string
${string:position} Extract substring from $string at $position
${string:position:length} Extract $length characters substring from $string at $position
${string#substring} Strip shortest match of $substring from front of $string
${string##substring} Strip longest match of $substring from front of $string
${string%substring} Strip shortest match of $substring from back of $string
${string%%substring} Strip longest match of $substring from back of $string
${string/substring/replacement} Replace first match of $substring with $replacement
${string//substring/replacement} Replace all matches of $substring with $replacement
${string/#substring/replacement} If $substring matches front end of $string, substitute $replacement for $substring
${string/%substring/replacement} If $substring matches back end of $string, substitute $replacement for $substring
See “Advanced Bash-Scripting Guide (tldp.org)” for additional information.