posix shell testing on various Unix-like systems circa 2003a script tested on: Mac OS 10.2.4, Linux, HP-UX 11i, and Korn in windo$. john meister ------------------------------------ ++++++++++++++++++++++++++++++++++++ original script: #!/bin/sh echo "This is a test script to ascertain the Posix compliance of your shell" echo "" # test one: backtick alternatives echo -n "1. The current date is:" echo $(date) # test two: expr versus $(( )) echo "2. The sum of 2+2 is: $((2 + 2))" # test three: variable slicing echo -n "3. The first character of the word 'xyzzy' is:" testvar="xyzzy" y=${testvar#?} # Lop off first char, assign to 7 z=${testvar%$y} # Lop off chars in y from end of x echo "$z" # test four, locale issues echo -n "4. The following should be the word 'BLETCHLEY' in lowercase:" echo BLETCHLEY | tr '[:upper:]' '[:lower:]' echo "5. The next line of output should be 'enigma', but not 'CODEBREAKER'" grep '[[:lower:]]' << EOF enigma CODEBREAKER EOF # sed portability echo "6. Checking to see if your sed implementation supports the -e flag:" echo " failure" | sed -e 's/fail/suc/' -e 's/ure/cess/' # multiple variable assignments on one line with no semicolon? a=1 b=2 c=3 echo "7. Multiple variable set test: a,b,c should count 1-3: $a, $b, $c" # does your sort support -u ? echo "8. Is sort -u supported? You should only see one occurance of 'yes' below" sort -u << EOF yes yes yes EOF echo "-------------------------" uname -a echo "-------------------------" echo "All done. Thanks!" exit 0 ++++++++++++++++++++++++++++++++++++ Script results: korn shell on Windows XP: =============================== Welcome to the Interix UNIX utilities. DISPLAY=JM2:0.0 $ cd /dev/fs/D $ vi test.sh $ ./test.sh This is a test script to ascertain the Posix compliance of your shell -n 1. The current date is: Tue Mar 11 19:48:27 PST 2003 2. The sum of 2+2 is: 4 -n 3. The first character of the word 'xyzzy' is: x -n 4. The following should be the word 'BLETCHLEY' in lowercase: bletchley 5. The next line of output should be 'enigma', but not 'CODEBREAKER' enigma 6. Checking to see if your sed implementation supports the -e flag: success 7. Multiple variable set test: a,b,c should count 1-3: 1, 2, 3 8. Is sort -u supported? You should only see one occurance of 'yes' below yes ------------------------- Interix JM2 3.0 SP-7.0.1701.1 x86 ------------------------- All done. Thanks! $ =================================== FROM MY HP C3000 running HP-UX 11i, Dec 2002 release root@hpc3000 [/root] >--> ./test.sh sh: ./test.sh: Execute permission denied. ----------------------------------------------------- root@hpc3000 [/root] >--> sh ./test.sh This is a test script to ascertain the Posix compliance of your shell -n 1. The current date is: Tue Mar 11 19:52:52 PST 2003 2. The sum of 2+2 is: 4 -n 3. The first character of the word 'xyzzy' is: x -n 4. The following should be the word 'BLETCHLEY' in lowercase: bletchley 5. The next line of output should be 'enigma', but not 'CODEBREAKER' enigma 6. Checking to see if your sed implementation supports the -e flag: success 7. Multiple variable set test: a,b,c should count 1-3: 1, 2, 3 8. Is sort -u supported? You should only see one occurance of 'yes' below yes ------------------------- HP-UX hpc3000 B.11.11 U 9000/785 2002751315 unlimited-user license ------------------------- All done. Thanks! ----------------------------------------------------- root@hpc3000 [/root] ========================================================== On my Linux system: ------------------------------------------------ john@cafe [/wagoneers/home/john] ------------------------------------------------ --> sh ./test.sh This is a test script to ascertain the Posix compliance of your shell 1. The current date is:Tue Mar 11 19:54:36 PST 2003 2. The sum of 2+2 is: 4 3. The first character of the word 'xyzzy' is:x 4. The following should be the word 'BLETCHLEY' in lowercase:bletchley 5. The next line of output should be 'enigma', but not 'CODEBREAKER' enigma 6. Checking to see if your sed implementation supports the -e flag: success 7. Multiple variable set test: a,b,c should count 1-3: 1, 2, 3 8. Is sort -u supported? You should only see one occurance of 'yes' below yes ------------------------- Linux cafe 2.0.37 #2 Thu May 13 12:28:17 PDT 1999 i686 unknown ------------------------- All done. Thanks! ------------------------------------------------ john@cafe [/wagoneers/home/john] ------------------------------------------------ ========================================================== ON MAC OS 10.2.4: -> more mac.results [john-n-:~] john% sh ./test.sh This is a test script to ascertain the Posix compliance of your shell 1. The current date is:Tue Mar 11 19:59:18 PST 2003 2. The sum of 2+2 is: 4 3. The first character of the word 'xyzzy' is:x 4. The following should be the word 'BLETCHLEY' in lowercase:bletchley 5. The next line of output should be 'enigma', but not 'CODEBREAKER' enigma [john-n-:~] john% ===================================================================== John Meister Adjunct Faculty - Computer Science Dept. ===================================================================== |
The Art of Linux System Administration published by O'Reilly Media Study Guide for the LPIC-2 Certification Exams |
Wagoneers FULL SIZE JEEPS JeepMeister "Jeep is America's -Enzo Ferrari MeisterTech Diesels + |
One Page Overview of Linux Commands click for an image of the 5 essential Linux commands An Intro to Linux |
at Midway Auto on SR9 in Snohomish, or at Northland Diesel in Bellingham, WA |