The tag has no wiki summary.

learn more… | top users | synonyms

2
votes
2answers
77 views

Output of stat on OSX

I want to use the stat command to get information on a file. I did this: Josephs-MacBook-Pro:Desktop Joseph$ echo 'hello' > info.txt Josephs-MacBook-Pro:Desktop Joseph$ stat info.txt 16777220 ...
29
votes
7answers
2k views

Is test or [ or [[ more portable both between bash shells and between other shells?

I see I can do $ [ -w /home/durrantm ] && echo "writable" writable or $ test -w /home/durrantm && echo "writable" writable or $ [[ -w /home/durrantm ]] && echo ...
3
votes
5answers
76 views

search a command in PATH with the same name of the script

For example, my script is $HOME/bin/sudo. I'd like to search for an executable in $PATH with the same name, sudo, and run it - but not the script $HOME/bin/sudo itself, otherwise I will run into an ...
2
votes
1answer
88 views

date command, going back one or two days. Seeing different flags

I'm writing a bash script that should run on OSX and Ubuntu. I'm not sure if this particular problem is due to an OS mismatch; more likely it's a difference in the date command on the two shells, ...
6
votes
1answer
276 views

Portability of an executable to another Linux machine

I've installed the program Motion on one Linux machine (M1) and want the same program on another (M2). There are various builds of this program, and I have forgotten which one I have used, so can I ...
3
votes
4answers
233 views

Test if command accepts a specific option

What is the preferred way to test if a command takes an option? What are the caveats? As a motivating example, at login my shell aliases grep to add several --exclude-dir options but this option is ...
4
votes
3answers
172 views

Frequency of words in non-English language text: how can I merge singular and plural forms etc.?

I'm sorting French language words in some text files according to frequency with a focus on insight rather than statistical significance. The challenge is about preserving accented characters and ...
5
votes
2answers
509 views

Does `sed` exist in all *nixes?

My application will be running on all versions of Unix-based OS, say, Linux, MacOS, HP-UX, Sun Solaris , OSX, etc. I'm using the following sed command in a common place to delete the string matched ...
4
votes
2answers
69 views

Find out extension of executable files?

When I am building software from source on a GNU+Linux system, during the ./configure stage I frequently see the following line: checking for suffix of executables... How do I create such a check ...
4
votes
2answers
168 views

Launching a terminal emulator without knowing which ones are installed

I need to write a script that will launch a terminal emulator and run a particular command in it. Since I don't know which terminal emulators have been installed on the target system, how could I find ...
2
votes
3answers
108 views

Standard and portable way to send email from console?

What is the most portable or standard way to send an email from the console or a script on Linux, and possibly Unix?
5
votes
2answers
681 views

Portability of file descriptor links

I've always wondered this but never took the time to find out, so I'll do so now - how portable is the usage shown here of either /proc/$$/fd/$N or /dev/fd/$N? I understand POSIX guarantees /dev/null, ...
5
votes
2answers
256 views

Which is the most portable of sed, awk, perl and sh?

Can someone put these tools in order of portability? Which of these is certain to be found on even the most minimal *nix systems? Is any of them 100% sure to be present? My guess is that the order is ...
6
votes
1answer
223 views

When is it important to write portable scripts?

Most code I write is in PHP. I have recently started learning shell scripting. Most of the resources and tutorials that I've come across are specific to Bash. Some warn about bashisms and some don't. ...
4
votes
2answers
970 views

tail -f, but with line numbers

I'm trying to see how many times foo bar appears in /var/log/foo.log within an arbitrary amount of time on a remote server, but nothing that I've tried so far has worked. I've already got a timer ...
1
vote
2answers
34 views

Can I use `type` to check whether an arbitrary name is a valid command name?

The bash built-in type can be used for this purpose by checking its exit status: Exit Status: Returns success if all of the NAMEs are found; fails if any are not found. How portable is it? The ...
15
votes
2answers
493 views

Use of ^ as a shell metacharacter

I wrote a small script today which contained grep -q ^local0 /etc/syslog.conf During review, a coworker suggested that ^local0 be quoted because ^ means "pipe" in the Bourne shell. Surprised by ...
4
votes
2answers
648 views

Is a ZFS storage array portable across operating systems & CPU Architectures?

I know that ZFS is available on variety of operating systems Solaris, Illumos, Linux, BSD etc. Suppose I have a bunch of disks that are part of ZFS raid file system that was created on Linux, could ...
13
votes
6answers
892 views

How to achieve portability with sed -i (in-place editing)?

I'm writing shell scripts for my server, which is a shared hosting running FreeBSD. I also want to be able to test them locally, on my PC running Linux. Hence, I'm trying to write them in a portable ...
13
votes
2answers
393 views

What is the most portable method of launching a terminal emulator?

Say I need to write a script that will launch a terminal and execute a command and I need that to work on various systems. How can I do that in a safe and portable manner? Is xterm always installed? ...
3
votes
2answers
329 views

Writing scripts that use different commands in different shells [duplicate]

How can I write a script that is shell independent? I want to be able to run one script which will run in ksh, sh and bash. For example: If I have a line in my script like whence ls which will run in ...
85
votes
3answers
5k views

Why not use “which”? What to use then?

When looking for the path to an executable or checking what would happen would you enter a command name in a Unix shell, there's a plethora of different utilities (which, type, command, whence, where, ...
1
vote
2answers
2k views

Is “/etc/issue” common for all Linux distributions?

I'm trying to Create OS detect portable function in bash script, So I just want to know, the file "/etc/issue" is common for all Linux Flavors ?
2
votes
2answers
343 views

Which systems do not honor socket read/write permissions?

man 7 unix on Linux states: In the Linux implementation, sockets which are visible in the file system honor the permissions of the directory they are in. Their owner, group and their ...
2
votes
2answers
127 views

overriding HOME location

I'd like to override the user's HOME location locally in a script in order to force an application to store/load its settings portably. export HOME=$TMPDIR/Data export XDG_CONFIG_HOME=$TMPDIR/Data ...
12
votes
6answers
2k 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 ...
4
votes
3answers
1k 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, ...
17
votes
2answers
16k views

Difference between 2>&-, 2>/dev/null, |&, &>/dev/null and >/dev/null 2>&1

Just looking for the difference between 2>&- 2>/dev/null |& &>/dev/null >/dev/null 2>&1 and their portability with non-Bourne shells like tcsh, mksh, etc.
9
votes
4answers
4k 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
1k 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 ...
17
votes
8answers
3k 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?
18
votes
4answers
1k 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 ...
17
votes
2answers
2k 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
268 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 ...
14
votes
3answers
21k 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 ...
16
votes
2answers
13k 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
165 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
7k 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 ...
6
votes
3answers
2k 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 ...
13
votes
10answers
2k views

Detect init system using the shell

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 ...
49
votes
6answers
1k 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 ...
10
votes
4answers
969 views

What makes a portable mp3 player work well with Linux?

I'm in the market for a new portable mp3-player, and will be connecting it mostly to a Linux box, but occasionally to a Windows Vista machine as well. I'm wondering what qualities I should be looking ...