The goal of this book is to document known and unknown methods of doing various tasks using only built-in bash features. Using the snippets from this bible can help remove unneeded dependencies from scripts and in most cases make them faster. I came across these tips and discovered a few while developing neofetch, pxltrm and other smaller projects.
The snippets below are linted using shellcheck and tests have been written where applicable. Want to contribute? Read the CONTRIBUTING.md. It outlines how the unit tests work and what is required when adding snippets to the bible.
See something incorrectly described, buggy or outright wrong? Open an issue or send a pull request. If the bible is missing something, open an issue and a solution will be found.
From one of my scripts: it will find a 64-bit 7z.exe if it was installed as part of the 7-zip installer, then run it with the parameters provided to the batch file.
setlocal
:verify7zip
:: registry trick from http://www.robvanderwoude.com/files/sortdate2_nt.txt
:: extra trick: tokens=2* allows to get the 3rd (and beyond: space delimited!) value in one variable %%b
for /F "tokens=2*" %%a IN ('REG QUERY "HKEY_LOCAL_MACHINE\SOFTWARE\7-Zip" /v Path64 2^>nul') do set sevenZipDirectoryPath=%%b
call :checkMissingSetting sevenZipDirectoryPath || goto :help
set sevenZipExeFilePath=%sevenZipDirectoryPath%7z.exe
if not exist "%sevenZipExeFilePath%" call :showError "No 7-zip executable at %sevenZipExeFilePath%" || goto :help
:run7zip
"%sevenZipExeFilePath%" %*
endlocal
goto :end
:checkMissingSetting
if not defined %1 call :notifyMissingSetting %1 && exit /b 1
call :showSetting %1
exit /b 0
goto :end
:notifyMissingSetting
echo Registry didn't provide the environment variable "%1"
goto :end
:showError
:: remove double quotes using tilde trick:
echo %~1
:help
echo Syntax: %0 7z.exe-commandline-parameters
goto :end
:end
Since it was not possible to install PowerShell 3 on ancient Windows Server 2003 and Windows Server 2003 R2 machines, I opted for this workaround during the time they were being retired:
I’ve investigating how much work it will be to migrate the machine, as opposed to adapting the scripts with Poshcode/Jaykul modules (of which many have external dependencies that I’d need to check first). It’s about the same order of magnitude, so I’ll be migrating the machine earlier. In the mean time, a different machine will run the scripts and access the required data over a network share.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters