Reputation: 79
I'm trying to make the following script run on SunOS 5.10 Generic_120011-14 sun4v sparc SUNW
, but I'm having difficulties with adjusting it.
#!/bin/bash
DIRECTORY=$1
if [ $# -eq 1 ]; then
if [ -d "$DIRECTORY" ]; then
find "$DIRECTORY" -mindepth 1 -printf '%y %p\n' | awk '$1=="d"{sub(/.*\//,"&DIR: ")} {gsub(/[^\/]*\//," ")} 1'
else
echo "That directory doesn't exist."
exit 1
fi
else
find . -mindepth 1 -printf '%y %p\n' | awk '$1=="d"{sub(/.*\//,"&DIR: ")} {gsub(/[^\/]*\//," ")} 1'
fi
Command find
doesn't have -printf
nor does it have -mindepth
. Any suggestions what should I use instead?
Upvotes: 0
Views: 512
Reputation: 30873
The problem is not Solaris specific, the problem is you are using GNU extensions so your script is not portable, i.e. not POSIX.
There are two ways to overcome the issue, either the GNU utilities you need are already installed on your Solaris 10 machine, and you just need to tell your script to use them, or they are not installed and you need to modify your script to use POSIX or at least Solaris standard options and syntax.
#!/bin/bash PATH=$PATH:/usr/sfw/bin:/usr/local/bin:/opt/csw/bin DIRECTORY=$1 if [ $# -eq 1 ]; then if [ -d "$DIRECTORY" ]; then gfind "$DIRECTORY" -mindepth 1 -printf '%y %p\n' | gawk '$1=="d"{sub(/.*\//,"&DIR: ")} {gsub(/[^\/]*\//," ")} 1' else echo "That directory doesn't exist." exit 1 fi else gfind . -mindepth 1 -printf '%y %p\n' | gawk '$1=="d"{sub(/.*\//,"&DIR: ")} {gsub(/[^\/]*\//," ")} 1' fi
#!/bin/ksh DIRECTORY=${1:-.} if [ ! -d "$DIRECTORY" ]; then echo "That directory doesn't exist." exit 1 fi find "$DIRECTORY" ! -name "$DIRECTORY" -exec \ ksh -c 'printf "%c %s\n" $(ls -dl "$1" | cut -c1-1) "$1"' sh {} \; | \ nawk '$1=="d"{sub(/.*\//,"&DIR: ")} {gsub(/[^\/]*\//," ")} 1'
Upvotes: 3