بنقرة واحدة
shell
// Shell scripting standards for SceneScape — shebang, style, and Bash guidelines.
// Shell scripting standards for SceneScape — shebang, style, and Bash guidelines.
Runtime test verification gate for SceneScape — image freshness checks, rebuild-before-test requirements, and retry policy.
Guide for creating SceneScape test cases — unit, functional, integration, UI, and smoke tests with positive and negative cases.
Procedures for updating SceneScape documentation — where to make changes and what to update for each type of modification.
JavaScript coding standards for SceneScape — code style, conventions, and frontend patterns.
Makefile standards for SceneScape — build targets, conventions, and patterns.
Python coding standards for SceneScape — imports, indentation, patterns, and conventions.
| name | shell |
| description | Shell scripting standards for SceneScape — shebang, style, and Bash guidelines. |
Use #!/usr/bin/env bash for portability:
#!/usr/bin/env bash
Not #!/bin/bash (less portable) or #!/bin/sh (POSIX only, limiting).
make lint-shell # Lint all .sh files
\ line continuationif [[ condition ]]; then
echo "Indented with 2 spaces"
if [[ nested ]]; then
echo "Nested indentation"
fi
fi
Use set -e to exit on any error:
#!/usr/bin/env bash
set -e # Exit immediately if a command fails
set -o pipefail # Fail if any command in pipeline fails
# Now any failing command will exit the script
command1
command2
command3
For critical scripts, use strict mode:
set -euo pipefail
# -e: exit on error
# -u: exit on undefined variable
# -o pipefail: fail on pipe errors
Clean up on exit or error:
cleanup() {
echo "Cleaning up..."
rm -f /tmp/tempfile
}
trap cleanup EXIT
trap 'echo "Error on line $LINENO"' ERR
lowercase_with_underscoresUPPERCASE_WITH_UNDERSCORESreadonly CONSTANT_VALUE# Local
local temp_file="/tmp/data"
local count=0
# Global/Environment
WORKSPACE_DIR="/workspace"
export DATABASE_PASSWORD
# Constants
readonly MAX_RETRIES=3
Always quote variables to prevent word splitting:
# Good
file_path="/path/with spaces/file.txt"
cat "$file_path"
# Bad - breaks with spaces
cat $file_path
# Use default if variable is unset
config_file="${CONFIG_FILE:-/etc/default.conf}"
# Use default if variable is unset or empty
database="${DATABASE_NAME:=scenescape}"
# Error if variable is unset
required="${REQUIRED_VAR:?Error: REQUIRED_VAR must be set}"
[[ ]] for TestsPrefer [[ ]] over [ ] or test:
# Good - modern test
if [[ -f "$file" ]]; then
echo "File exists"
fi
if [[ "$value" == "expected" ]]; then
echo "Match"
fi
# Pattern matching
if [[ "$filename" == *.txt ]]; then
echo "Text file"
fi
# File tests
[[ -f "$file" ]] # File exists
[[ -d "$dir" ]] # Directory exists
[[ -r "$file" ]] # Readable
[[ -w "$file" ]] # Writable
[[ -x "$file" ]] # Executable
# String tests
[[ -z "$string" ]] # Empty string
[[ -n "$string" ]] # Non-empty string
[[ "$a" == "$b" ]] # Equal
[[ "$a" != "$b" ]] # Not equal
# Numeric tests
[[ "$a" -eq "$b" ]] # Equal
[[ "$a" -ne "$b" ]] # Not equal
[[ "$a" -lt "$b" ]] # Less than
[[ "$a" -gt "$b" ]] # Greater than
# Execute command2 only if command1 succeeds
command1 && command2
# Execute command2 only if command1 fails
command1 || command2
# Multiple conditions
[[ -f "$file" ]] && [[ -r "$file" ]] && cat "$file"
function_name() {
local arg1="$1"
local arg2="$2"
# Function body
echo "Processing: $arg1, $arg2"
return 0
}
# Call function
function_name "value1" "value2"
check_status() {
if [[ condition ]]; then
return 0 # Success
else
return 1 # Failure
fi
}
# Use return value
if check_status; then
echo "Check passed"
else
echo "Check failed"
fi
Always use local for function variables:
process_data() {
local input="$1"
local temp_file="/tmp/temp_$$"
# Process data
# ...
}
Use $() instead of backticks:
# Good
current_date=$(date +%Y-%m-%d)
file_count=$(ls | wc -l)
# Avoid (backticks)
current_date=`date +%Y-%m-%d`
# Iterate over list
for item in item1 item2 item3; do
echo "$item"
done
# Iterate over files
for file in /path/*.txt; do
[[ -f "$file" ]] && process "$file"
done
# C-style loop
for ((i = 0; i < 10; i++)); do
echo "Iteration $i"
done
# Read file line by line
while IFS= read -r line; do
echo "Line: $line"
done < input.txt
# Condition-based
count=0
while [[ $count -lt 10 ]]; do
echo "$count"
((count++))
done
# Declare array
declare -a services=("controller" "manager" "autocalibration")
# Access elements
echo "${services[0]}" # First element
echo "${services[@]}" # All elements
echo "${#services[@]}" # Array length
# Iterate
for service in "${services[@]}"; do
echo "Service: $service"
done
services+=("mapping")
if command_that_might_fail; then
echo "Success"
else
echo "Failed with exit code: $?"
exit 1
fi
error_exit() {
echo "Error: $1" >&2
exit 1
}
# Usage
[[ -f "$config_file" ]] || error_exit "Config file not found: $config_file"
set -x # Enable debug output (prints each command)
# Commands here will be echoed
set +x # Disable debug output
# Read entire file
content=$(cat file.txt)
# Read line by line
while IFS= read -r line; do
echo "$line"
done < file.txt
# Overwrite
echo "content" > file.txt
# Append
echo "more content" >> file.txt
# Here document
cat > config.txt << EOF
setting1=value1
setting2=value2
EOF
temp_file=$(mktemp)
trap "rm -f '$temp_file'" EXIT
# Use temp file
echo "data" > "$temp_file"
# Get script directory
script_dir=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
# Construct absolute paths
config_file="$script_dir/config.txt"
filepath="/path/to/file.txt"
dirname=$(dirname "$filepath") # /path/to
basename=$(basename "$filepath") # file.txt
filename="${basename%.*}" # file
extension="${basename##*.}" # txt
# Start background job
long_running_command &
pid=$!
# Wait for specific job
wait $pid
# Wait for all background jobs
wait
# Compare outputs of two commands
diff <(command1) <(command2)
# Read from command output
while read -r line; do
echo "$line"
done < <(command)
# Build with progress
env BUILDKIT_PROGRESS=plain docker build \
--build-arg VERSION="$VERSION" \
-t "scenescape-service:$VERSION" \
.
# Check required variables
: "${SUPASS:?SUPASS environment variable must be set}"
: "${DATABASE_PASSWORD:?DATABASE_PASSWORD must be set}"
# Get variables from Makefile
VERSION=$(cat version.txt)
BUILD_DIR="${BUILD_DIR:-build}"
retry_command() {
local max_attempts=3
local attempt=1
while [[ $attempt -le $max_attempts ]]; do
if command_to_retry; then
return 0
fi
echo "Attempt $attempt failed, retrying..." >&2
((attempt++))
sleep 2
done
return 1
}
validate_input() {
local input="$1"
if [[ -z "$input" ]]; then
echo "Error: Input cannot be empty" >&2
return 1
fi
if [[ ! "$input" =~ ^[0-9]+$ ]]; then
echo "Error: Input must be numeric" >&2
return 1
fi
return 0
}
log() {
echo "[$(date +'%Y-%m-%d %H:%M:%S')] $*"
}
log_error() {
echo "[$(date +'%Y-%m-%d %H:%M:%S')] ERROR: $*" >&2
}
log "Starting process"
log_error "Something went wrong"
❌ Don't use eval (security risk):
# Bad
eval "$user_input"
# Good - use arrays or proper quoting
args=("$arg1" "$arg2")
command "${args[@]}"
❌ Don't parse ls output:
# Bad
files=$(ls *.txt)
for file in $files; do
process "$file"
done
# Good
for file in *.txt; do
[[ -f "$file" ]] && process "$file"
done
❌ Don't use cat unnecessarily:
# Bad (useless use of cat)
cat file.txt | grep pattern
# Good
grep pattern file.txt
❌ Don't ignore errors:
# Bad
command_that_might_fail
# Good
if ! command_that_might_fail; then
echo "Command failed" >&2
exit 1
fi
Test scripts with:
bash -n script.sh # Syntax check
shellcheck script.sh # Linting
bash -x script.sh # Debug mode
# Test edge cases
test_script() {
./script.sh "" # Empty input
./script.sh "normal" # Normal input
./script.sh "with spaces" # Spaces
./script.sh "$long_string" # Long input
}
#!/usr/bin/env bash
# SPDX-FileCopyrightText: (C) 2025 Intel Corporation
# SPDX-License-Identifier: Apache-2.0
#
# Script Name: deploy.sh
# Description: Deploy SceneScape services to production
# Usage: ./deploy.sh [environment]
#
set -euo pipefail
#
# Function: process_data
# Description: Process input data and generate output
# Arguments:
# $1 - Input file path
# $2 - Output directory
# Returns:
# 0 on success, 1 on error
#
process_data() {
local input_file="$1"
local output_dir="$2"
# ...
}
# Slower - creates subshell
count=$(expr $count + 1)
# Faster - built-in arithmetic
((count++))
# Prefer bash built-ins over external commands
[[ "$string" == *pattern* ]] # Built-in pattern matching
# vs
echo "$string" | grep pattern # External process
SceneScape uses bash, not POSIX sh. These are OK:
[[ ]] tests$() command substitution(( )) arithmetic[[ =~ ]] regex matchingBut prefer portable constructs when they work equally well.