The portability tag has no wiki summary.
3
votes
2answers
27 views
Portable way to get script's absolute path?
What is a portable way for a (zsh) script to determine its absolute path?
On Linux I use something like
mypath=$(readlink -f $0)
...but this is not portable. (E.g., readlink on darwin does not ...
1
vote
3answers
49 views
How to share a GNU sed script between Linux and Mac OS X
I have a GNU sed script I use on Linux; it is installed at /bin/sed and it seems it contains GNUisms. I have collaborators using Mac OS X. They have installed (non-GNU) sed, located at /usr/bin/sed, ...
5
votes
4answers
233 views
Is it recommended to use zsh instead of bash scripts?
Can I assume that enough people have zsh installed to run scripts with a
#!/usr/bin/env zsh
as shebang?
Or will this make my scripts un-runnable on too many systems?
Clarification: I’m interested ...
4
votes
2answers
477 views
What's a safe and portable way to split a string in shell programming?
When writing a shell script, I often want to split a string. Here's a very simple example:
for dir in $(echo $PATH | tr : " "); do
[[ -x "$dir"/"$1" ]] && echo $dir
done
This will ...
14
votes
6answers
1k views
The most universal scripting language for Linux is?
We are writing scripts for Linux systems, there has been some debate over what would be the most universally Linux present scripting language to use. Bash, SH, Posix? What?
12
votes
4answers
599 views
How universal is sudo?
I was writing some instructions on how to install something (TeX-related - if you don't ask, I won't ruin your day by supplying more details) and used sudo to install system-wide. Someone commented ...
11
votes
2answers
510 views
Portability of “> /dev/stdout”
Occasionally I need to specify a "path-equivalent" of one of the standard IO streams (stdin, stdout, stderr). Since 99% of the time I work with Linux, I just prepend /dev/ to get /dev/stdin, etc., ...
1
vote
2answers
161 views
Why does awk print on non-null strings and positive numbers
I've noticed some awk examples which use 1 instead of print to print $0 (eg. To conserve space, I normally use '1'. and on this site).
Is this a documented / safe practice, or is is it subject to ...
10
votes
3answers
4k views
Testing if a variable is empty in a shell script
I have seen the following technique used many times on many different shells, to test if a variable is empty:
if [ "x$1" = "x" ]; then
# Variable is empty
fi
Are there any advantages on using ...
15
votes
2answers
4k views
tar cvf or tar -cvf ?
I have learned to use tar without '-' for options, like tar cvfz dir.tar.gz Directory/ but I recently came accross the slightly different tar -czvf syntax (I think the 'f' must be the last option in ...
3
votes
1answer
118 views
Testing equivalence for exit status
Are the following two command lists portably equivalent?
$foo; echo $? #(1)
and
$foo && echo 0 || echo $? #(2)
Postscript
Consider the command exit-status defined so:
#!/bin/sh
exit ...
3
votes
2answers
3k views
Search string in many files on HP-UX
I need to find which files (they can have space in the filename) of a directory contains a string using only sh and system's commands (Perl is not an option).
For a few files, this command works ...
4
votes
3answers
281 views
On which unix distributions is Python installed as part of the default install?
Does anyone know of an overview that would document on which (recent) UNIX distributions Python is available by default, i.e. part of the default installation?
PS: Answers from StackOverflow, before ...
4
votes
2answers
256 views
Bash- detect init system
This may have more to do with detecting operating systems, but I specifically need the init system currently in use on the system.
Fedora 15 now uses systemd, Ubuntu uses Upstart, while others use ...
43
votes
5answers
845 views
Resources for portable shell programming
What resources exist for portable shell programming? The ultimate answer is to test on all targeted platforms, but that's rarely practical.
The POSIX / Single UNIX specification is a start, but it ...