I'm fairly new to Linux and I have used batch files to do batch tasks easily. I have this script that scans the folders found inside the source folder and then creates a symbolic link off each compressed Zip archive found inside to the destination folder.
What the script does is that it goes out of the current directory twice, enters a folder called projects, then another folder called example inside and finally into a folder called release.
Within the release folder are a bunch of other folders (i.e version 1
, version 2
, version 3
, etc.) and inside these folders is a Zip archive.
The next part of the script is that it goes through the folders version 1
, version 2
, version 3
, etc. and then creates a symbolic file of the Zip archive found inside to the destination folder.
This for loop continues on until there are no remaining archive files to create a symbolic link of.
The script looks like this, there are comments left as a guideline:
@echo off
REM Sets the location of directories to be used in the script
REM The source folder has more folders inside with compressed ZIP archives
set source=%~dp0..\..\projects\example\release
REM The destination folder is where all the compressed ZIP archives will go to
set destination=%~dp0destination
REM A for-loop in-charge of searching for all compressed ZIP archives inside the folders in the source directory
for /D %%i in ("%source%\*") do (
REM A for-loop that grabs every compressed ZIP archives found inside the folders in the source directory
for %%j in ("%%~fi\*.zip") do (
del "%destination%\%%~ni_%%~nj.zip" >nul 2>nul
REM Creates a symbolic link for each compressed ZIP archive found to the destination directory
mklink "%destination%\%%~ni_%%~nj.zip" "%%j" 2>nul
)
)
REM This creates a new line
echo.
REM Displays an error message that the script is not run as an administrator, and a guide for potential troubleshooting if the script is already run as an administrator
if %errorlevel% NEQ 0 echo *** ERROR! You have to run this file as administrator! ***
if %errorlevel% NEQ 0 echo *** If you are getting this error even on administrator, please create the 'destination' folder ***
REM Prompts the user for any key as an input to end the script
pause
The directory structure and contents looks about like this:
.
└── Example
└── Release
├── Version 1
│ └── version1.zip
├── Version 2
│ └── version2.zip
├── Version 3
│ └── version3.zip
└── Version 4
└── version4.zip
Each symbolic link created by the script should be named in 2 parts, the first part is what folder it came from and the second part is simply project. So if it came from the Version 1
folder, the symbolic link would be called Version 1-project.zip
in the destination folder.
How would I go about to converting this to a shell script? I know not every feature in a Windows batch script isn't available in bash
and that's okay because I can omit some parts of the script. Thank you in advance.
tree
command), and then tell us what result you expect from that example. That way, we can understand what you need and be able to help you.