Do all technical naming in English:
* variables
* functions
* comments
* ...
Text output may of course be in any language.
Loglevel?
Shell script:
i=1
for f in *.dpx; do
mv $f $(printf %07d $i).dpx
i=$((i+1))
done
Shell script:
# Set start number of output files:
i=1
# Iterate through all DPX image files:
for FILE in *.dpx; do
# zero-pad index to 7 digits:
INDEX=$(printf "%07d" $i)
mv $FILE $INDEX.dpx
# Increment counter:
i=$((i+1))
doneSome variables are already configured in your environment. For your convenience.
Examples: Where’s the program folder? Where’s my home?
Batchfile:
set
echo %ProgramFiles%
Shell script:
printenv
env
echo "$HOME"env vs printenv? See question #123473 on stackexchange.com
“Do something, until / while / for something. Then move on.”
Here’s the basic idea of a FOR loop:
for X in Y do ...
Sufficient for most things :)
:: IN (Start, Stepsize, Maximum)
FOR /L %%I IN (0, 2, 8) DO echo Index is: %%I
echo.
:: IN (a b c d e ...)
FOR %%I IN (1 2 3) DO echo Index is: %%I
echo.
:: %* = %1 %2 %3 ...
FOR %%F IN (%*) DO echo Params: %%F
Batch file:
@echo off
FOR /R "C:\Videos\" %%F IN (*.avi) DO (
echo %%~nF
)
pause
Shell script:
for FILE in ~/Videos/*.avi; do
echo "${FILE%.*}"
doneVariable with modifier Description
%~I Expands %I which removes any surrounding
quotation marks ("").
%~fI Expands %I to a fully qualified path name.
%~dI Expands %I to a drive letter only.
%~pI Expands %I to a path only.
%~nI Expands %I to a file name only.
%~xI Expands %I to a file extension only.
%~sI Expands path to contain short names only.
%~aI Expands %I to the file attributes of file.
%~tI Expands %I to the date and time of file.
%~zI Expands %I to the size of file.
%~$PATH:I Searches the directories listed in the PATH environment
variable and expands %I to the fully qualified name of
the first one found. If the environment variable name is
not defined or the file is not found by the search,
this modifier expands to the empty string.
${#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.
Use the loop examples to:
Hint: Drag-and-Drop stuff on “loop_examples.bat”