Questions tagged [sh]

sh is the standard Unix shell since Version 7 Unix. POSIX has standardized shell behavior based on the Bourne Shell, and portable shell scripts should conform to the standardized syntax. Use this tag for questions that apply to Bourne/POSIX-style shells. For shell scripts with errors, please check them in http://shellcheck.net before posting here.

sh, aka the Bourne Shell, is the standard Unix shell since v7 Unix, in standard location /bin/sh.

POSIX has since standardized shell behavior based on the Bourne Shell, and portable shell scripts should conform to the standardized syntax.

The most common successor to the Bourne Shell (sh) is - The Bourne-Again SHell and many Unix-like operating systems have /bin/sh linked to the bash executable; when bash is called as sh, it runs in a (mostly) POSIX-compliant mode.

The Stack Overflow tag wiki has a large FAQ section; many of the questions and answers there also pertain to (many variants of) sh.

The (Debian Almquist shell) is also used as a small and fast POSIX-compliant shell for running shell scripts; Debian and Ubuntu systems have /bin/sh linked to the dash executable.

Tools

  • checkbashisms (from the devscripts package) is a useful tool for ensuring that a shell script is POSIX-compliant and does not use features not specified by POSIX.

  • ShellCheck is a web application that analyses shell scripts and checks for common mistakes (both syntax and semantic errors) as well as compliance with the POSIX standard, e.g., it highlights unquoted variables and Bashisms (if sh is used in the shebang). It can also be installed as an off-line command-line tool; see the repository in GitHub for more information.

7327 questions
2
votes
2 answers

filtering html tag in linux with sed

I'm having a problem trying to filter the following string in unix into: 20121209/YvegRascYTGxmWLUIrqW/por121209130030.jpg and 2012-12-09 13:00. I can find…
John Lopez
  • 23
  • 3
2
votes
1 answer

standardizing prompts across shells in cygwin

I'm having a heck of a time standardizing my prompts across the different shells I have installed for cygwin. Installed shells: bash (default login shell) sh csh (tcsh, actually) ksh zsh My prompt is standardized across bash, csh, and zsh, but I…
nullrevolution
  • 3,477
  • 15
  • 19
2
votes
1 answer

What does the "< " symbol mean on -jar call?

I'm facing a problem with calling java from php on a linux server with popen. $java = '/usr/bin/java'; $cmd = "$java -jar javafiles/register.jar < $tmpFile"; What does the < before $tmpFile mean? Because apparently it is loading the content of…
2
votes
1 answer

Linux recycle bin script

I'm creating a recycle-bin script in SH shell linux in three differant scripts, delete, trash and restore. The first two scripts are working fine; 'Delete' moves the selected file to the recycle-bin while logging a text file called 'trashinfo'…
2
votes
2 answers

adding text to the middle of a line

I am in need of assistance adding text to a few places in a line of text using sed or awk. This is the output of the df command that I have written to test.txt fsu:/dev/sda3 34407336 3348680 29282672 11% / fsu:/dev/sda1 …
2
votes
2 answers

Print stdout in Python without shell escape sequences

I'm using sh to run git commands inside a Python script. In [1]: from sh import git In [2]: s = git("log", "-1", pretty="format:%h %s") In [3]: print s 4f14a66 basic debug page This seems to work as expected. However, using this in a Django…
Wilfred Hughes
  • 26,027
  • 13
  • 120
  • 177
2
votes
1 answer

Are these shell script characters ( || : ) doing anything useful?

I have a little shell script that runs anything executable in a designated directory, while passing along two arguments: #!/bin/sh cd '/foo' for s in bar/*; do [ -x $s ] && $s "$1" "$2" || : ; done Is the || : bit serving any purpose? I wanted the…
NReilingh
  • 1,218
  • 12
  • 24
2
votes
6 answers

Script to Shutdown Ubuntu

I want to write a script which can Shutdown remote Ubuntu system. Actually i want my VM to shutdown safely when i shutdown my main machine on which my VM is installed . Is there is any of doing this with the help of Sh scripts or script written in…
user2173955
2
votes
5 answers

Allow another user to control the process

I have an sh script which runs on our server. It is started with nohup from another script so that i can easily close session and it still runs Main script (which will start this one) is also an sh script. And it can be executed with two parameters:…
Alexey Kamenskiy
  • 2,560
  • 3
  • 31
  • 51
2
votes
5 answers

How to run a command from a variable in shell scripting

How to run a command after assigning it to some variable in shell scripting? example: command_name=echo Now, is there a way to use "$command_name hello world" instead of "echo hello world" ?
Nathan Pk
  • 639
  • 4
  • 18
  • 25
2
votes
3 answers

Shell scripting to print list of elements

Is there any command in shell scripting which is similar to "list" in tcl? I want to write a list of elements to a file (each in separate line) .But, if the element matches a particular pattern then element next to it and the element itself should…
Nathan Pk
  • 639
  • 4
  • 18
  • 25
2
votes
0 answers

How do i import CSV files into couchdb update existing data, insert new records, delete old records

What I'm trying to do is import a CSV or TSV file into couchdb update records that have changes to them, remove records (or mark as not active) that are no longer in the csv file, and insert new records into the database. I need to keep all the…
Brad
  • 2,211
  • 5
  • 38
  • 68
2
votes
3 answers

command return in shell script

I have developed a script shell in OpenWrt as below, I noticed a strange behavior (the "return") as shown in my comments at the end of script. It returns 43 instead of 9003 and 45 instead of 9005, do you have any explanation for this…
developer
  • 4,188
  • 5
  • 33
  • 50
2
votes
1 answer

Command-line tool to substitute environment variables

I am interested if there is a UNIX tool which replaces occurences of $VAR or ${VAR} (for all existing variables in the env, not just one) with the actual values of environment variables. This replacment is in a plain text file, not a bash script; a…
user1046334
2
votes
2 answers

Generating sh code from within sh: Escaping

I have a shell variable (we shall call x) containing a string with shell meta characters. For example, I might have abc "def's" ghi as set by x='abc "def'\''s" ghi' I want to build a shell command from that string (to be stored in a file, not…
ikegami
  • 322,729
  • 15
  • 228
  • 466
1 2 3
99
100