The tag has no usage guidance.

learn more… | top users | synonyms

5
votes
2answers
62 views

Is getopts always be available for Bash?

Can I use getopts for parsing command-line arguments in my bash scripts(not sh) without worrying about another depedency?
3
votes
1answer
64 views

A common way of combining two files in Solaris and Linux

I am trying to write a script that would combine two files into one and should work in both Solaris 5.10 and a Linux box. File1: dit710 dit710 dit720 dit720 File2: FacA D0000000000000001 FacA ...
1
vote
1answer
158 views

How / Is it possible to install python in a portable way?

I'm working on a python script which takes care to migrate a mysql database with a certain schema / structure, into a postgresql database with a different structure. During the development phase I ...
5
votes
3answers
574 views

sending output to /dev/stderr vs. >&2

In scripts, errors are usually sent to file descriptor 2 with &2, ie: echo "error" >&2 Sometimes /dev/stderr is used instead: echo "error" > /dev/stderr Looking at /dev/stderr, I ...
3
votes
2answers
76 views

avoid multiple pipes broken due to missing command

In shell scripts I often use multiple pipes like this: cmd1 | cmd2 | cmd3 Now if cmd2 is missing the pipe will result "broken" and cmd3 won't receive any input. As workaround I could test ...
1
vote
3answers
85 views

Predefined group ids across Linux distros?

In order to successfully implement w/r access via ACL for external storage with ext4 fs I need to assign default group id for files on storage. LSB_5.0.0 say: This specification makes no attempt to ...
4
votes
1answer
58 views

Bash script for showing newly introduced env variables

I'm making this test script to help me reverse engineer scripts in charge of setting the dev environment. The script: #env-changes #!/bin/bash TESTED_SCRIPT=$1 shift ENV_BEFORE=$(env | sort) . $...
16
votes
4answers
790 views

checkbashisms-compliant way to determine the current shell

In my .profile, I use the following code to ensure that Bash-related aliases and functions are only sourced if the login shell actually is Bash: # If the current (login) shell is Bash, then if [ "${...
1
vote
1answer
105 views

how can one manually assign a permanent / static IP address with “ip addr add”?

After an IP address is assigned to this network interface, with any of the the following commands: ip addr add 10.0.0.0 dev eth1 valid_lft forever preferred_lft forever ip addr replace 10.0.0.0 dev ...
75
votes
9answers
5k views

On what systems is //foo/bar different from /foo/bar?

Throughout the POSIX specification, there's provision (1, 2, 3...) to allow implementations to treat a path starting with two / specially. A POSIX application (an application written to the POSIX ...
9
votes
2answers
2k views

Is the “$?” (dollar-question mark) variable available only in the Bash shell?

In the Bash shell, I can get the command exit status through the $? variable: # ps -ef | grep "haha" root 15439 15345 0 23:02 pts/0 00:00:00 grep --color=auto haha # echo $? 0 Is it ...
2
votes
1answer
199 views

how to force shell script characters encoding from within the script

I have a few shell scripts with UTF8-encoded characters inside and i want to be sure that they are decoded correctly regardless of the machine locale settings. Is it possible to force the shell (bash ...
7
votes
5answers
715 views

How to programmatically detect awk flavor (e.g. gawk vs nawk)

I'm using a command-line application which is essentially a collection of bash shell scripts. The application was written to run on BSD/OSX and also on Linux. One of the scripts relies on awk. It ...
1
vote
2answers
83 views

What is the difference between bash script and shell script [duplicate]

As there are different kinds of shells, What is the difference between bash and shell scripts and is there any compatible script on can write that runs on al unix shells
1
vote
2answers
82 views

Portable binaries and the libexec path

I want to build portable binaries for apache mesos. One of the problems is that it uses some binaries located in the libexec folder during execution. When compiling, I set --prefix to /tmp/test. The ...
1
vote
1answer
53 views

How reliable/portable are Nix built-ins/commands (echo, ps, sort, uniq) from Debian to other distros

I've coded a script and am wondering about it's reliability / portability. #!/bin/bash threadsPlease() { ps -mo lwp,c -p $1 | sort -gk 2 | uniq -f 1 } THREAD_LINE=$( threadsPlease $1 | grep -v - |...
1
vote
3answers
77 views

How to rewrite grep call from Linux to AIX

In my Linux system in fgrep I am using atributes -m 500 -C 0. But on AIX I didnt see these arguments. So how should I rewrite it? I just read to use awk instead of fgrep but I don't know how.
4
votes
1answer
239 views

awk/nawk alternative on SunOs and Linux

I have a script that basically checks the Java version on the box it's running on and does whatever based on the version number. My problem is that I want to use the same command on both SunOs and ...
1
vote
0answers
35 views

How can I easily deal with differences between BSD and GNU sed? [duplicate]

BSD and GNU sed have some small differences in what arguments they accept. I just learned that I have to use different command lines when using -i: sed -i '' # BSD sed -i # GNU I solved this ...
2
votes
1answer
83 views

how can I run old programs from a MIPS?

I have an old PC with a program called atomTV, for viewing, and producing movies from molecular trajectory files. I only have a binary, and the platform it ran on was 64-bit MIPS architecture, where I ...
3
votes
2answers
227 views

Which shells don't support dollar-parenthesis expansion, and demand backticks?

The modern recommendation is to use: $(...) instead of the older: `...` mainly for readability and to avoid the need for escaping when nesting. Which shells do not support the $(...) form, and ...
0
votes
1answer
124 views

Which version of split supports flag -p?

This command does not work in GNU Coreutils split, split of Cern Linux 5 (Redhat) and BSD (Apple Yosemite 10.10.3): split -p'\0' input.txt where input.txt is masi\0hello\0world. Some comments ...
12
votes
1answer
863 views

How to execute an arbitrary simple command over ssh without knowing the login shell of the remote user?

ssh has an annoying feature in that when you run: ssh user@host cmd and "here's" "one arg" Instead of running that cmd with its arguments on host, it concatenates that cmd and arguments with spaces ...
8
votes
6answers
6k views

How can I safely get the version of ksh?

How can I safely get the version of ksh from within a ksh script? I have seen the following solutions: ksh --version echo ${.sh.version} echo $KSH_VERSION And given the right circumstances, each ...
3
votes
1answer
109 views

Why can't Adobe Flash for Mac run on Linux?

As we know, Adobe no longer develops new Flash versions for Linux (except for Google Chrome, i know). It does, however, develop actively Flash for Windows and Mac. Linux can run native Windows ...
0
votes
1answer
431 views

Can I run files from Ubuntu in Mint?

I was wondering, since recently I've decided I want to move from Ubuntu 14.04 to XFCE mint linux, if games installed in Ubuntu will run in Mint? I've copied my home folder onto an external hard drive, ...
3
votes
2answers
65 views

How to deal with utilities with same name but behave differently between Unix variants?

For some reason, I chose Macbook as my computer to managing remote Linux servers. Sometimes I will encounter troubles with those utilities which have the same name but behave differently between ...
3
votes
0answers
105 views

find printf switch POSIX alternative

I'd like to rewrite these 2 command so they will use only POSIX-complaint switches: find "$TARGET_DIR" -maxdepth 1 -type d -printf '(DIR) %f\n' find "$TARGET_DIR" -maxdepth 1 -type f -printf '%s %f ...
6
votes
5answers
591 views

execute a command in $PATH matching a wildcard

I'd like to find and execute a command in the current $PATH matching this wildcard libreoffice?.? (eg. libreoffice4.0, libreoffice4.3, etc.) EDIT: if multiple matches are found, you can pick one ...
21
votes
5answers
3k views

Generating a random password; why isn't this portable?

I want to generate a random password, and am doing it like so: </dev/urandom tr -dc [:print:] | head -c 64 On my laptop, which runs Ubuntu, this produces only printable characters, as intended. ...
5
votes
2answers
2k 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 ...
36
votes
7answers
3k 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 "writable"...
3
votes
6answers
211 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 ...
3
votes
1answer
4k 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, ...
7
votes
1answer
1k 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
797 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
340 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
554 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
240 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
1k 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 ...
3
votes
3answers
219 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?
7
votes
2answers
2k 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, ...
9
votes
2answers
585 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 ...
10
votes
2answers
515 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. ...
9
votes
4answers
9k 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
44 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 ...
19
votes
3answers
832 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 ...
6
votes
2answers
1k 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 ...
24
votes
7answers
5k 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 ...
14
votes
2answers
718 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? ...