Parameterized Script Examples

Parameterized scripts can be created in various scripting languages, depending on the platform. The following table provides the scripting languages supported by platforms to create parameterized scripts:

Platform Scripting Language

Windows

  • PowerShell-Script
  • Python
  • VBScript

Linux, Unix, or Mac

  • Lua
  • Perl
  • Python
  • Shell 

For instructions on creating a parameterized script, refer to Creating Parameterized Script.

Script Examples

This section provides script examples based on the selected platform and scripting language. Each example demonstrates how to use parameters within the script to customize its behavior. These examples can serve as a starting point for creating your own parameterized scripts.

The prefix is not required to be included in the parameter name.

Windows Platform

Windows: PowerShell-ScriptWindows: PowerShell-Script

Value: C:\Users\Public\service.exe
Parameter: fullFilePath

param (
    [string]$fullFilePath
)
# Delete the file
Remove-Item -Path $fullFilePath -Force -ErrorAction Stop 

Windows: PythonWindows: Python

Value: C:\Users\Public\service.exe
Parameter: file_path

import os
import sys
file_path = sys.argv[1]
os.remove(file_path)
print(f"Deleted: {file_path}") 

Windows: VBScriptWindows: VBScript

Value: C:\Users\Public\service.exe
Paramater: filePath

Dim filePath
filePath = WScript.Arguments(0)
Set fso = CreateObject("Scripting.FileSystemObject")
fso.DeleteFile filePath
Linux, Unix, or Mac Platform

Linux, Unix, or Mac Platform: LuaLinux, Unix, or Mac Platform: Lua

Value: /root/dev/service.sh
Parameter: file_path

local file_path = arg[1]
os.remove(file_path)
print("Deleted: " .. file_path) 

Linux, Unix, or Mac Platform: PerlLinux, Unix, or Mac Platform: Perl

Value: /root/dev/service.sh
Parameter: file_path 

use strict;
use warnings;
my $file_path = $ARGV[0];
if (!$file_path) {
    die "Usage: perl script.pl <full_file_path>\n";
}
unlink $file_path or die "Failed to delete $file_path: $!\n";
print "Deleted: $file_path\n"; 

Linux, Unix, or Mac Platform: PythonLinux, Unix, or Mac Platform: Python

Value: /root/dev/service.sh
Parameter: file_path

import os
import sys
file_path = sys.argv[1]
os.remove(file_path)
print(f"Deleted: {file_path}") 

Linux, Unix, or Mac Platform: ShellLinux, Unix, or Mac Platform: Shell

Value: /root/dev/service.sh
Parameter: fullFilePath

#!/bin/bash
fullFilePath="$1" # Define the file path (e.g. '/root/dev/service.sh')
# Delete the file
rm "$fullFilePath" 

Related Topics

Creating Parameterized Script