First 15 rows of sh
| uuidstring | contentstring | content_formatstring | raw_contentstring | taskstring | analysisstring | solutionstring | teststring | full_contentstring | full_content_formatstring |
|---|---|---|---|---|---|---|---|---|---|
| 0649453d-8ae2-4553-9e0a-2a9998adb626 | # Write a Bash function named `print_parameters` that accepts command-line arguments via `$@` and prints each argument with its position number, starting from 1, in the format `Parameter #<n> = <value>` where `<n>` is a positive integer and `<value>` is the argument string. The f… | code comment | #!/bin/bash # display command line options count=1 while [[ -n "$1" ]]; do echo "Parameter #$count = $1" count=$(( $count + 1 )) shift done |
| Write a Bash function named `print_parameters` that accepts command-line arguments via `$@` and prints each argument with its position number, starting from 1, in the format `Parameter #<n> = <value>` where `<n>` is a positive integer and `<value>` is the argument string. The fun… |
| The solution must iterate over all positional parameters without disturbing the caller's `$@`. The key is to copy arguments into a local array first, then iterate over the array indices and values. The algorithm: (1) copy all function arguments into a local array using `local -a … |
| #!/bin/bash set -euo pipefail # Print each positional parameter with its 1-based index. print_parameters() { local -a args=("$@") local count=1 local value for value in "${args[@]}"; do printf 'Parameter #%d = %s\n' "$count" "$value" count=$((co… |
| assert_equal() { local expected="$1" local actual="$2" if [[ "$actual" != "$expected" ]]; then printf 'Assertion failed: expected %q, got %q\n' \ "$expected" "$actual" >&2 exit 1 fi } # Test with multiple arguments output=$(print_para… |
| # Write a Bash function named `print_parameters` that accepts command-line arguments via `$@` and prints each argument with its position number, starting from 1, in the format `Parameter #<n> = <value>` where `<n>` is a positive integer and `<value>` is the argument string. The f… |
| commented standard order |
| 769de1ef-0f61-42cf-9abf-1c2a25966a03 | # Write a Bash function named `compare_numbers` that accepts two integer arguments, compares them, and prints exactly one line to standard output: `num1>num2` if the first argument is greater than the second, `num1<num2` if the first is less than the second, and `num1==num2` if t… | code comment | #!/bin/bash NUM1=100 NUM2=200 if(($NUM1>$NUM2));then echo "num1>num2" else echo "num1<num2" fi | Write a Bash function named `compare_numbers` that accepts two integer arguments, compares them, and prints exactly one line to standard output: `num1>num2` if the first argument is greater than the second, `num1<num2` if the first is less than the second, and `num1==num2` if the… | The solution uses Bash's arithmetic evaluation `((...))` which handles integer comparisons directly and treats inputs as base-10 integers. The main algorithm first validates that exactly two arguments are provided and that both are valid integers using a pattern match to allow an… | #!/bin/bash set -euo pipefail # Compare two integers and print the relationship. compare_numbers() { local first="$1" local second="$2" # Validate both arguments are integers (allow optional leading minus) if [[ ! "$first" =~ ^-?[0-9]+$ ]] || [[ ! "$second" =~ … | assert_equal() { local expected="$1" local actual="$2" if [[ "$actual" != "$expected" ]]; then printf 'Assertion failed: expected %q, got %q\n' \ "$expected" "$actual" >&2 exit 1 fi } # Valid comparisons assert_equal "num1>num2" "$(co… | # Write a Bash function named `compare_numbers` that accepts two integer arguments, compares them, and prints exactly one line to standard output: `num1>num2` if the first argument is greater than the second, `num1<num2` if the first is less than the second, and `num1==num2` if t… | solution-first order |
| db828279-aa18-4386-a7e1-7f94fad6ec85 | # Write a Bash function named `classify_ip` that accepts a single argument, a dotted-quad IPv4 address string such as `192.168.1.1` or `10.0.0.1`. The function must convert the address to a 32-bit unsigned integer, then determine which special address classifications it belongs t… | code comment | uint_max=4294967295 d_10_0_0_0=167772160 d_10_255_255_255=184549375 d_172_16_0_0=2886729728 d_172_31_255_255=2887778303 d_192_168_0_0=3232235520 d_192_168_255_255=3232301055 d_169_254_0_0=2851995648 d_169_254_255_255=2852061183 d_127_0_0_0=2130706432 d_127_255_255_255=214748… | Write a Bash function named `classify_ip` that accepts a single argument, a dotted-quad IPv4 address string such as `192.168.1.1` or `10.0.0.1`. The function must convert the address to a 32-bit unsigned integer, then determine which special address classifications it belongs to:… | The solution requires parsing a dotted-quad string into a 32-bit integer value. The key challenges are: (1) correctly validating each octet as a decimal integer between 0 and 255 without allowing leading zeros (except the single digit "0"), (2) ensuring exactly four octets separa… | #!/bin/bash set -euo pipefail # Classify an IPv4 dotted-quad address into private, link-local, loopback, and multicast. classify_ip() { local ip="$1" local -a octets local value=0 local octet local i # Split the input on dots; read -ra stores all fields… | assert_equal() { local expected="$1" local actual="$2" if [[ "$actual" != "$expected" ]]; then printf 'Assertion failed: expected %q, got %q\n' "$expected" "$actual" >&2 exit 1 fi } # Valid addresses with standard classifications assert_equal "yes… | # Write a Bash function named `classify_ip` that accepts a single argument, a dotted-quad IPv4 address string such as `192.168.1.1` or `10.0.0.1`. The function must convert the address to a 32-bit unsigned integer, then determine which special address classifications it belongs t… | test-first order |
| 34f08a95-7131-4458-b91f-e41f957d29c2 | # Write a Bash function named `first_ascii` that takes a single non-empty string as its first argument, extracts the first character of that string using a portable parameter expansion method that works in both Bash and POSIX shells, converts that character to its ASCII decimal v… | code comment | ############################################################################### # # This bench is perf testing methods of getting ASCII value of the first # character in a string. # # $ shellbench -c -s zsh,ksh93,bash,dash ./str_first_ascii.sh # -------------------------------… | Write a Bash function named `first_ascii` that takes a single non-empty string as its first argument, extracts the first character of that string using a portable parameter expansion method that works in both Bash and POSIX shells, converts that character to its ASCII decimal val… | The core challenge is extracting the first byte of a string in a shell‑portable way and then converting that byte to its ASCII decimal value. The snippet provided benchmarks several methods. The most portable and efficient method for character extraction is `${txt%%"${txt#?}"}`: … | #!/bin/bash set -euo pipefail # Print the ASCII decimal value of the first byte of the given non-empty string. first_ascii() { local input="$1" local first_byte local ascii_value if [[ -z "$input" ]]; then printf 'Error: input string is empty\n' >&2 … | assert_equal() { local expected="$1" local actual="$2" if [[ "$actual" != "$expected" ]]; then printf 'Assertion failed: expected %q, got %q\n' \ "$expected" "$actual" >&2 exit 1 fi } # Basic tests assert_equal "72" "$(first_ascii "He… | # Write a Bash function named `first_ascii` that takes a single non-empty string as its first argument, extracts the first character of that string using a portable parameter expansion method that works in both Bash and POSIX shells, converts that character to its ASCII decimal v… | commented standard order |
| 1870ed49-c39e-47f1-bdf7-cb6eeea3adf0 | # Write a Bash function named `check_number` that accepts exactly one command-line argument: a base-10 integer. The function must print exactly one line: `the entered number is greater than or equal to 100` if the integer is 100 or greater, or `the entered number is less than 100… | code comment | NUMBER=$1 if [ $NUMBER -ge 100 ] then echo "the entered number is greater than or equal to 100" else echo "the entered number is less than 100" fi | Write a Bash function named `check_number` that accepts exactly one command-line argument: a base-10 integer. The function must print exactly one line: `the entered number is greater than or equal to 100` if the integer is 100 or greater, or `the entered number is less than 100` … | The solution uses Bash's built-in arithmetic evaluation `(( ))` to compare the numeric argument against 100. Since the input may contain spaces or unusual formatting, we first validate that exactly one argument was provided. The argument is treated as a base-10 integer; Bash stri… | #!/bin/bash # Check if a provided number is >= 100 or < 100. check_number() { if [[ $# -ne 1 ]]; then printf 'Error: exactly one argument required\n' >&2 return 2 fi local number="$1" if (( number >= 100 )); then echo "the entered number… | assert_equal() { local expected="$1" local actual="$2" if [[ "$actual" != "$expected" ]]; then printf 'Assertion failed: expected %q, got %q\n' \ "$expected" "$actual" >&2 exit 1 fi } assert_equal "the entered number is greater than o… | Write a Bash function named `check_number` that accepts exactly one command-line argument: a base-10 integer. The function must print exactly one line: `the entered number is greater than or equal to 100` if the integer is 100 or greater, or `the entered number is less than 100` … | test-first order |
| 03176f25-827f-482f-800c-48268a987e2b | # Write a Bash function that implements a number-guessing game where the computer picks a random number between 0 and 10 inclusive. The function should accept the maximum number of attempts as its first argument (defaulting to 10 if not provided), and the target number as its sec… | code comment | #!/bin/bash max=10 number=$7 while true; do echo "guess a number between 0-10" read guess if [ "$guess" = "$number" ]; then echo "yay you guessed it" break elif [ "$guess" -lt "$number" ]; then echo "your number was too low" else echo "your number was too high" fi d… | Write a Bash function that implements a number-guessing game where the computer picks a random number between 0 and 10 inclusive. The function should accept the maximum number of attempts as its first argument (defaulting to 10 if not provided), and the target number as its secon… | The solution requires a loop that continues until either the user guesses correctly or the maximum number of attempts is exhausted. The main algorithm: validate the guess is a non-negative integer (using regex or arithmetic check), compare it to the target using arithmetic compar… | #!/bin/bash set -euo pipefail # Play a number guessing game with configurable attempt limit and target number. guess_the_number() { local max_attempts="${1:-10}" local target="${2:-$((RANDOM % 11))}" local attempts=0 local guess # Validate and normalize max… | assert_equal() { local expected="$1" local actual="$2" if [[ "$actual" != "$expected" ]]; then printf 'Assertion failed: expected %q, got %q\n' \ "$expected" "$actual" >&2 exit 1 fi } # Test correct guess on first try output=$(printf … | Write a Bash function that implements a number-guessing game where the computer picks a random number between 0 and 10 inclusive. The function should accept the maximum number of attempts as its first argument (defaulting to 10 if not provided), and the target number as its secon… | commented standard order |
| fb7e99ce-6a87-4108-b00c-e43a12c14e6e | Write a Bash function named `is_prime` that accepts a single base-10 integer as its first argument and prints one of two messages: if the number is prime, print exactly `<number> is a prime number.`; otherwise, print `<number> is not a prime number.` where `<number>` is the origi… | markdown | #!/bin/bash echo -e "Enter Number : \c" read n for((i=2; i<=$n/2; i++)) do ans=$(( n%i )) if [ $ans -eq 0 ] then echo "$n is not a prime number." exit 0 fi done echo "$n is a prime number." | Write a Bash function named `is_prime` that accepts a single base-10 integer as its first argument and prints one of two messages: if the number is prime, print exactly `<number> is a prime number.`; otherwise, print `<number> is not a prime number.` where `<number>` is the origi… | The algorithm checks divisibility from 2 up to `n/2` (inclusive) using a loop. If any divisor divides `n` evenly (remainder 0), the number is composite and the function prints "not prime". If no divisor is found, the number is prime. Edge cases: for `n` ≤ 1, it is not prime; for … | #!/bin/bash set -euo pipefail # Check whether a given non-negative integer is prime. # Prints the result message and always returns 0 on successful execution. is_prime() { local n="$1" local i local ans if (( n <= 1 )); then printf '%s is not a prime nu… | assert_equal() { local expected="$1" local actual="$2" if [[ "$actual" != "$expected" ]]; then printf 'Assertion failed: expected "%s", got "%s"\n' \ "$expected" "$actual" >&2 exit 1 fi } assert_equal "0 is not a prime number." "$(is_… | # Write a Bash function named `is_prime` that accepts a single base-10 integer as its first argument and prints one of two messages: if the number is prime, print exactly `<number> is a prime number.`; otherwise, print `<number> is not a prime number.` where `<number>` is the ori… | standard order |
| 4814a9ab-5291-4c40-9bf1-243ef50c3dc9 | # Write a Bash function named `check_year` that accepts exactly two arguments: a year (a non-negative base-10 integer) and a type string (`even`, `odd`, `uspres`, `nonpres`, or `nonuspres`). The function must print nothing to standard output. It must exit with status 0 if the yea… | code comment | #! /bin/sh : 'This file is in the public domain, so clarified as of' : '2006-07-17 by Arthur David Olson.' case $#-$1 in 2-|2-0*|2-*[!0-9]*) echo "$0: wild year - $1" >&2 exit 1 ;; esac case $#-$2 in 2-even) case $1 in *[24680]) exit 0 ;; *) exit 1 ;; esac… | Write a Bash function named `check_year` that accepts exactly two arguments: a year (a non-negative base-10 integer) and a type string (`even`, `odd`, `uspres`, `nonpres`, or `nonuspres`). The function must print nothing to standard output. It must exit with status 0 if the year … | The core logic is to validate the two arguments first. For the year, strip leading zeros carefully (since `008` should be treated as 8), but allow the string `0`. Reject any string with characters other than digits (use a pattern match). For the type, check exact matches. For the… | #!/bin/bash set -euo pipefail # Validate a year and a type; exit 0/1 based on the condition, 2 on invalid input. check_year() { local year="$1" local type="$2" # Validate year: must be a non-negative base-10 integer. if [[ ! "$year" =~ ^[0-9]+$ ]]; then … | assert_equal() { local expected="$1" local actual="$2" if [[ "$actual" != "$expected" ]]; then printf 'Assertion failed: expected %q, got %q\n' "$expected" "$actual" >&2 exit 1 fi } # Helper to run check_year and capture exit status. run_check() {… | # Write a Bash function named `check_year` that accepts exactly two arguments: a year (a non-negative base-10 integer) and a type string (`even`, `odd`, `uspres`, `nonpres`, or `nonuspres`). The function must print nothing to standard output. It must exit with status 0 if the yea… | commented standard order |
| a925d163-a6b2-48ad-847b-7a2a284a51b4 | Write a Bash function named `bingo_call` that accepts a single integer argument between 1 and 75 (inclusive). The function must simulate a Bingo number generator by printing exactly one line to standard output in the format `The next number is, <LETTER>:<NUMBER>`, where `<LETTER>… | no fence | #!/bin/bash # Bingo Number Generator echo -e "\n~~ Bingo Number Generator ~~\n" NUMBER=$(( RANDOM % 75 + 1 )) TEXT="The next number is, " if (( NUMBER <= 15 )) then echo $TEXT B:$NUMBER elif [[ $NUMBER -le 30 ]] then echo $TEXT I:$NUMBER elif (( NUMBER < 46 )) then echo… | Write a Bash function named `bingo_call` that accepts a single integer argument between 1 and 75 (inclusive). The function must simulate a Bingo number generator by printing exactly one line to standard output in the format `The next number is, <LETTER>:<NUMBER>`, where `<LETTER>… | The solution first validates that exactly one argument is provided, that it is a valid base-10 integer (using regex `^[0-9]+$`), and that it is within 1–75. If any check fails, print an error to stderr and return 1. For a valid number, use a series of arithmetic comparisons to de… | #!/bin/bash set -euo pipefail # Print a Bingo call label for a given number 1-75, or exit with error. bingo_call() { if [[ $# -ne 1 ]]; then printf 'Error: exactly one argument required.\n' >&2 return 1 fi local number="$1" if [[ ! "$number" =~… | assert_equal() { local expected="$1" local actual="$2" if [[ "$actual" != "$expected" ]]; then printf 'Assertion failed: expected %q, got %q\n' \ "$expected" "$actual" >&2 exit 1 fi } # Valid inputs and expected output assert_equal "T… | # Write a Bash function named `bingo_call` that accepts a single integer argument between 1 and 75 (inclusive). The function must simulate a Bingo number generator by printing exactly one line to standard output in the format `The next number is, <LETTER>:<NUMBER>`, where `<LETTE… | solution-first order |
| a8882d7c-530e-45e3-ac8a-4ba58e448b02 | # Write a Bash function named `factorial` that accepts one command-line argument: a non-negative integer \(n\) (base-10, between 0 and 20, inclusive). The function must compute the factorial of \(n\) (i.e., \(n! = n \times (n-1) \times \cdots \times 1\), with the convention that … | code comment | #!/bin/bash read -p "enter a number:" n fact=1 while [ $n -gt 1 ] do fact=$(( $fact * $n )) n=$((n - 1)) done echo "factorial="$fact | Write a Bash function named `factorial` that accepts one command-line argument: a non-negative integer \(n\) (base-10, between 0 and 20, inclusive). The function must compute the factorial of \(n\) (i.e., \(n! = n \times (n-1) \times \cdots \times 1\), with the convention that \(… | The core algorithm is an iterative loop that multiplies a running product by each integer from \(n\) down to 2 (or from 2 up to \(n\)), which correctly computes \(n!\) for \(n \ge 1\), while \(0! = 1\) is handled by initializing the product to 1 and skipping the loop when \(n = 0… | #!/bin/bash set -euo pipefail # Compute the factorial of a non-negative integer and print "factorial=<value>". factorial() { local n="$1" local fact=1 local i # Validate input: integer, non-negative, and not causing 64-bit overflow. if [[ ! "$n" =~ ^[0-9]+$… | assert_equal() { local expected="$1" local actual="$2" if [[ "$actual" != "$expected" ]]; then printf 'Assertion failed: expected %q, got %q\n' \ "$expected" "$actual" >&2 exit 1 fi } # Valid inputs assert_equal "factorial=1" "$(facto… | Write a Bash function named `factorial` that accepts one command-line argument: a non-negative integer \(n\) (base-10, between 0 and 20, inclusive). The function must compute the factorial of \(n\) (i.e., \(n! = n \times (n-1) \times \cdots \times 1\), with the convention that \(… | standard order |
| e6520dde-fbc7-4afc-9dd4-69b65c6644a8 | # Write a Bash function named `extract_linker_version` that reads a linker version string from the first argument. The input string follows the format output by GNU ld's `--version` command, e.g., "GNU ld (GNU Binutils for Ubuntu) 2.38". The function must extract the version numb… | code comment | #!/usr/bin/awk -f # extract linker version number from stdin and turn into single number { gsub(".*\\)", ""); gsub(".*version ", ""); gsub("-.*", ""); split($1,a, "."); print a[1]*100000000 + a[2]*1000000 + a[3]*10000; exit } | Write a Bash function named `extract_linker_version` that reads a linker version string from the first argument. The input string follows the format output by GNU ld's `--version` command, e.g., "GNU ld (GNU Binutils for Ubuntu) 2.38". The function must extract the version number… | The approach is to process the input string in stages. First, remove everything up to and including the last closing parenthesis if present, because the version number typically appears after the parentheses (e.g., "GNU ld (GNU Binutils for Ubuntu) 2.38"). If there is no parenthe… | #!/bin/bash set -euo pipefail # Extract linker version number from a version string and convert to a single integer. # Usage: extract_linker_version "string" # Prints the integer and returns 0 on success, or 1 if no version found. extract_linker_version() { local input="$1"… | assert_equal() { local expected="$1" local actual="$2" if [[ "$actual" != "$expected" ]]; then printf 'Assertion failed: expected %q, got %q\n' \ "$expected" "$actual" >&2 exit 1 fi } # Test cases assert_equal "238000000" "$(extract_l… | # Write a Bash function named `extract_linker_version` that reads a linker version string from the first argument. The input string follows the format output by GNU ld's `--version` command, e.g., "GNU ld (GNU Binutils for Ubuntu) 2.38". The function must extract the version numb… | standard order |
| 075e80c8-27ba-4564-b085-652b8c9738c7 | Write a Bash function named `generate_mmap_flags` that accepts three directory paths as arguments: a Linux UAPI header directory, an asm-generic header directory, and an architecture-specific UAPI header directory. The function must parse `mman.h` files from these directories to … | no fence | if [ $# -ne 3 ] ; then [ $# -eq 1 ] && hostarch=$1 || hostarch=`uname -m | sed -e s/i.86/x86/ -e s/x86_64/x86/` linux_header_dir=tools/include/uapi/linux header_dir=tools/include/uapi/asm-generic arch_header_dir=tools/arch/${hostarch}/include/uapi/asm else linux_header_dir=$… | Write a Bash function named `generate_mmap_flags` that accepts three directory paths as arguments: a Linux UAPI header directory, an asm-generic header directory, and an architecture-specific UAPI header directory. The function must parse `mman.h` files from these directories to … | The solution processes up to four header files in a specific priority order, extracting macro definitions using a regular expression that matches `#define MAP_<name> <hex_value>`. The main algorithm involves: 1. Validating that all three required directory paths exist and corresp… | #!/bin/bash set -euo pipefail # Generate C array initializer for mmap flags from header directories. generate_mmap_flags() { local linux_header_dir="$1" local header_dir="$2" local arch_header_dir="$3" local linux_mman="${linux_header_dir}/mman.h" local arch… | assert_equal() { local expected="$1" local actual="$2" if [[ "$actual" != "$expected" ]]; then printf 'Assertion failed: expected %q, got %q\n' \ "$expected" "$actual" >&2 exit 1 fi } # Create temporary test directory structure with m… | Write a Bash function named `generate_mmap_flags` that accepts three directory paths as arguments: a Linux UAPI header directory, an asm-generic header directory, and an architecture-specific UAPI header directory. The function must parse `mman.h` files from these directories to … | standard order |
| fb7d9b24-efbb-4f72-97e7-976f867bef18 | # Write a Bash function named `generate_madvise_table` that accepts an optional directory path as its first argument. If no argument is provided, use `tools/include/uapi/asm-generic/` as the default directory. The function must search for a file named `mman-common.h` within the s… | code comment | [ $# -eq 1 ] && header_dir=$1 || header_dir=tools/include/uapi/asm-generic/ printf "static const char *madvise_advices[] = {\n" regex='^[[:space:]]*#[[:space:]]*define[[:space:]]+MADV_([[:alnum:]_]+)[[:space:]]+([[:digit:]]+)[[:space:]]*.*' grep -E $regex ${header_dir}/mman-comm… | Write a Bash function named `generate_madvise_table` that accepts an optional directory path as its first argument. If no argument is provided, use `tools/include/uapi/asm-generic/` as the default directory. The function must search for a file named `mman-common.h` within the spe… | The core algorithm processes a C header file to extract macro definitions. The approach: first validate that the argument (if provided) is a non-empty string, then construct the full path by appending `/mman-common.h`. Use `grep -E` with a regular expression that matches lines st… | #!/bin/bash set -euo pipefail # Generate a C array initializer from MADV_* macros in mman-common.h generate_madvise_table() { local header_dir="${1:-tools/include/uapi/asm-generic/}" local header_file="$header_dir/mman-common.h" local regex='^[[:space:]]*#[[:space:]… | assert_equal() { local expected="$1" local actual="$2" if [[ "$actual" != "$expected" ]]; then printf 'Assertion failed: expected %q, got %q\n' \ "$expected" "$actual" >&2 exit 1 fi } # Create temporary directory and test files tmpdir… | # Write a Bash function named `generate_madvise_table` that accepts an optional directory path as its first argument. If no argument is provided, use `tools/include/uapi/asm-generic/` as the default directory. The function must search for a file named `mman-common.h` within the s… | commented standard order |
| 631cc4c6-55f0-43d6-9bc0-3b1e6a8f1337 | # Write a Bash function named `format_variables` that accepts no arguments and works with the following global variables defined before the function is called: `name` (a string without spaces), `count` (a non-negative integer), and `items` (a string containing comma-separated val… | code comment | #!/bin/bash # Bash no tiene tipado fuerte, por lo que sus variables pueden tomar valores # de distintos tipos (cadenas de texto, numéricos, arreglos) sin necesidad # de hacer declaraciones. # # Los nombres de variable pueden contener caracteres alfanuméricos y guiones # bajos ("… | Write a Bash function named `format_variables` that accepts no arguments and works with the following global variables defined before the function is called: `name` (a string without spaces), `count` (a non-negative integer), and `items` (a string containing comma-separated value… | The solution must read the global variables, check that all three are set and non-empty (using `${var:-}` to detect empty/unset), and then process the comma-separated `items` string. The main algorithm splits `items` on commas into an array using `IFS=','` with `read -r -a`, then… | #!/bin/bash set -euo pipefail # Print formatted output using the global variables name, count, items. format_variables() { local name_val="${name:-}" local count_val="${count:-}" local items_val="${items:-}" if [[ -z "$name_val" || -z "$count_val" || -z "$items… | assert_equal() { local expected="$1" local actual="$2" if [[ "$actual" != "$expected" ]]; then printf 'Assertion failed: expected %q, got %q\n' \ "$expected" "$actual" >&2 exit 1 fi } # Test case 1: normal input name="John" count=3 it… | # Write a Bash function named `format_variables` that accepts no arguments and works with the following global variables defined before the function is called: `name` (a string without spaces), `count` (a non-negative integer), and `items` (a string containing comma-separated val… | test-first order |
| 89f7e40a-b3e3-4ae3-8a5f-3389318c7a20 | Write a Bash function named `auth_gate` that takes exactly three arguments: a username string, a password string, and a role string. The function must implement the following authentication logic: - If the role is `cleetus` and the password is `passw0rd`, extract the third char… | no fence | #!/bin/bash if [ ${#} -eq 3 ] then if [ ${3} = "cleetus" ] then if [ ${2} = "passw0rd" ] then #variable=q var1=${1:2:1} #arrays start at 0 D: if [ $var1 = "q" ] then echo "SUCCESS!!!" exit 1 else echo "cable issue, try again" exit 2 fi e… | Write a Bash function named `auth_gate` that takes exactly three arguments: a username string, a password string, and a role string. The function must implement the following authentication logic: - If the role is `cleetus` and the password is `passw0rd`, extract the third char… | The solution follows a straightforward nested conditional structure mirroring the original logic. First, verify that exactly three arguments are provided; otherwise print `tree` and return 4. Then compare the role argument with the two valid roles. For `cleetus`, first check the … | #!/bin/bash set -euo pipefail # Authenticate based on username, password, and role; prints a message and returns a status code. auth_gate() { if [[ $# -ne 3 ]]; then echo "tree" return 4 fi local username="$1" local password="$2" local role=… | assert_equal() { local expected="$1" local actual="$2" if [[ "$actual" != "$expected" ]]; then printf 'Assertion failed: expected %q, got %q\n' \ "$expected" "$actual" >&2 exit 1 fi } # Capture output and exit status run_and_check() {… | # Write a Bash function named `auth_gate` that takes exactly three arguments: a username string, a password string, and a role string. The function must implement the following authentication logic: # - If the role is `cleetus` and the password is `passw0rd`, extract the third … | standard order |