OS-SCO-Linux

From KRayWiki
Jump to navigation Jump to search
See Also 
OS-SCO

Workarounds for various deviations between Linux and SCO OpenServer 5.0.7 commands.

External Links

  1. Rosetta Stone for Unix

Built-in Alternatives

awk -v RS=""

Whereas GNU awk can accept backslash escapes for carriage-return, line-feed, and form-feed characters, SCO's native awk cannot. For example:

$ awk -v RS="[\r]*[\f\n]+[\r]*" ' { print } ' LO 
awk: input record `
SULPHUR SPRINGS I....' too long
source line 1 of program << { print } >>

tr or sed are useful for clearing unwanted characters.

sed offers the most flexible replacement options as it accepts regular expressions.
SCO's version is very limited in its ability to interpret backslash escapes. Control characters are entered into the pattern verbatim.
For example, to place a carriage-return in a pattern, type <Ctrl>+<V><Ctrl>+<M> into it.
tr can replace characters, delete (-d) characters, and compress (-s) series of identical characters.

The issue with backslash escapes may be more simple. SCO's awk generally rejects literal line-feeds in strings. For example:

# Non-zero PAGEHEAD indicates report header processing active.
PAGEHEAD = 1 
awk: newline in string \LO-M.txt...
at line 4 of program << \
BEGIN ... >>
context is
REM = " \ >>>
<<<

awk delete array [subscript]

It was a surprise to find SCO Openserver 5.0.7 awk calls delete array a syntax error though the man page says the subscript is optional.

$ awk 'BEGIN { A[1] = 0; delete A; }' 
awk: Syntax error  
at line 1 of program << BEGIN { A[1] = 0; de ... >> 
context is 
BEGIN { A[1] = 0; delete >>> A; <<< 
awk: illegal statement 
at line 1 of program << BEGIN { A[1] = 0; de ... >> 

It was more surprising to find that delete array[subscript], while not shown as an error, also did not work, and that many variants on array[subscript] = "" were equally ineffective.

/usr/bin/awk -> /opt/K/SCO/Unix/5.0.7Hw/usr/bin/awk 

The work around from https://unix.stackexchange.com/questions/147957/delete-an-array-in-awk

split("", array, ":") 

dos2unix / unix2dos

$ dtox / xtod 
CRLF/LF text file line delimiter translation.
dtox / xtod are filters, so use output redirection to write to a file other than the original file.

ex

$ ex 
a text editor
The -c command-line argument implementation varies from system to system.
On SCO Unix where vi is not supplied by gvim:
$ ls -l `which ex`
lrwxrwxrwx 1 root root 34 May 5 2008 /usr/bin/ex -> /opt/K/SCO/Unix/5.0.7Hw/usr/bin/vi
$ man ex
...
-c command
Execute the specified command at start up. Individual
commands can be separated by vertical bar characters
``|``.
...
When ex is a gvim component:
$ man ex
...
−c command
Specify an initial command to be executed in the first edit
buffer loaded from an existing file (see the EXTENDED
DESCRIPTION section). Implementations may support more than
a single −c option. In such implementations, the specified
commands shall be executed in the order specified on the com‐
mand line.
...
The SCO variant DOES NOT support multiple -c arguments, but documents that multiple commands are possible via vertical bar delimiters.
The gvim variant DOES implement the vertical bar delimiter, even though it is not documented in the associated man page.
For cross-platform compatibility, use the vertical bar delimiter rather than multiple -c arguments.

find

$ find . -maxdepth 0 
List only items in the current directory without traversing into a sub-directory.
Increase the number to increase the number of levels below the current directory to traverse.
Whereas find on Linux supports -maxdepth, find SCO version of find does not.
For the specific case of $ find . -maxdepth 0, the following is a possible workaround:
$ find . -level 0 | grep -v '/'
The issue is that while -maxdepth references the current directory, -level refers to the content of a sub-directory of the current folder.

groups

$ id -Gn 
List a user's /etc/group memberships.
Whereas id -Gn and groups on Linux produce identical, one-line output, the SCO command outputs multiple lines of text that lists certain group memberships on multiple lines.
See groups under Alternative Linux Workarounds for other solutions that more closely emulate the output of the Linux command.

ltrace / strace

$ truss 

sed with \n

Whereas GNU's sed can split an input line into multiple output line, SCO's native sed command cannot.

$ echo split:me | sed -e "s/:/\n/g" 

SCO's tr command can split input lines. For example:

$ echo split:me | tr ":" "\n" 
Caveat: Whereas a GNU sed script could replace a single character with multiple characters, tr replaces characters on a one-for-one basis.

su -l / su --login

$ su - 
-, -l, and --login are synonyms on Linux.

whoami

$ id -un 
Output is identical to that of the Linux command.
$ who am i 
Output is significantly different than that of the Linux command.

Alternative Workarounds

groups

A possible workaround that produces output similar to Linux:

function groups () { awk \ -v U="$1" \ -v G=`id -gn $1` \ 'BEGIN \ { FS=":"; printf("%s", G) } $0 ~ "^" G "$" \ { next } $0 ~ "([:,])" U "([:,]|\$)" \ { printf(" %s", $1) } END \ { print "" } ' /etc/group }
function () is a BASH shell construct that can be put into the users environment.
To use the workaround in a shell without functions, put the awk code in a PATHed executable script.