xref: /aosp_15_r20/external/shflags/examples/hello_world.sh (revision 63d4e48fb639f6414be0db9d718e3be2667e4fed)
1*63d4e48fSSadaf Ebrahimi#!/bin/sh
2*63d4e48fSSadaf Ebrahimi#
3*63d4e48fSSadaf Ebrahimi# This is the proverbial 'Hello, world!' script to demonstrate the most basic
4*63d4e48fSSadaf Ebrahimi# functionality of shFlags.
5*63d4e48fSSadaf Ebrahimi#
6*63d4e48fSSadaf Ebrahimi# This script demonstrates accepts a single command-line flag of '-n' (or
7*63d4e48fSSadaf Ebrahimi# '--name'). If a name is given, it is output, otherwise the default of 'world'
8*63d4e48fSSadaf Ebrahimi# is output.
9*63d4e48fSSadaf Ebrahimi
10*63d4e48fSSadaf Ebrahimi# Source shflags.
11*63d4e48fSSadaf Ebrahimi. ../shflags
12*63d4e48fSSadaf Ebrahimi
13*63d4e48fSSadaf Ebrahimi# Define a 'name' command-line string flag.
14*63d4e48fSSadaf EbrahimiDEFINE_string 'name' 'world' 'name to say hello to' 'n'
15*63d4e48fSSadaf Ebrahimi
16*63d4e48fSSadaf Ebrahimi# Parse the command-line.
17*63d4e48fSSadaf EbrahimiFLAGS "$@" || exit 1
18*63d4e48fSSadaf Ebrahimieval set -- "${FLAGS_ARGV}"
19*63d4e48fSSadaf Ebrahimi
20*63d4e48fSSadaf Ebrahimiecho "Hello, ${FLAGS_name}!"
21