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.

8493 questions
2
votes
2 answers

Convert signed int number to unsigned whith shell script

I need to convert signed int32 number to unsigned using shell script for example : convert Input : -256 Expected output: 4294967040
Songe
  • 39
  • 1
  • 8
2
votes
1 answer

Checking whether a filename matches a pattern in bash

I am trying to figure out how to setup a script that will do the following: files in dir: a_3.txt b_3.txt c_3.txt script(s) in dir: 1.sh # run this for a_*.txt 2.sh # run this for b_*.txt or c_*.txt I need to have a function that will…
Jazzkatt
  • 65
  • 2
  • 8
2
votes
3 answers

How to add values in awk

I have file which has log size like, 10.80 kb 60.08 kb 35.40 kb 2.20 MB 1.10 MB 40.80 kb 3.15 MB 20.50 kb I want to add awk one liner in such a way that it satisfy below conditions, Convert kb to MB (divide by 1000) get total in MB I have…
Rock
  • 157
  • 1
  • 3
  • 13
2
votes
1 answer

Iterating over a range of dates in a unix shell script

I am trying to create a script in which 4 days ago date should be equal to to current date if it is not then add 1 more day and check. Below is the one i have created but still not clear about answer. #!/bin/bash batchdate=`date --date "4 day ago"…
Amit Alone
  • 21
  • 3
2
votes
3 answers

Is it possible to set variables equal to expressions in UNIX?

In Unix, how would one do this? #!/bin/sh x=echo "Hello" | grep '^[A-Z]' I want x to take the value "Hello", but this script does not seem to work. What would be the proper way of spelling something like the above out?
Waffles
  • 447
  • 2
  • 5
  • 11
2
votes
1 answer

Check if a variable has a specific string in it in an if statement

I am trying to check to see if a string exists inside a variable inside an if statement. if [ -n $(echo "$RUN" | grep "Done running command.") ]; then I know this can be done by creating another variable then checking if that is empty but I am…
2
votes
1 answer

Quickest way to modify md5 hash value of a zip file

I have around 500 zip files that i have to place in a directory for a process to process them. The process calculates the md5 hash value of the file before processing it. If the hash value of the file is the same as one it is aware of (stored in a…
ziggy
  • 15,677
  • 67
  • 194
  • 287
2
votes
1 answer

The function definitions in shell use dash

The following code: #!/bin/bash function me-test() { echo 'test' } me-test The execution method below is not correct: #sh 1.sh 1.sh: line 6: `me-test': not a valid identifier but the execution method below is correct: #./1.sh test In…
baozailove
  • 159
  • 2
  • 14
2
votes
3 answers

Newlines not quoted properly in ls -Q

Using ls -Q with --quoting-style=shell, newlines in file names (yes, I know...) are turned into ?. Is this a bug? Is there a way how to get the file names in a format that's 100% compatible with a shell (sh or bash if possible)? Example (bash): $…
choroba
  • 231,213
  • 25
  • 204
  • 289
2
votes
1 answer

Alpine linux in docker container ignoring shell script arguments

I'm trying to create a docker image which sets a custom tomcat port (I know you can set an external port with the docker flag "-p 8888:8080" but for my use case I want to change the internal port as well). When I try to start catalina.sh the run…
Sean Nelson
  • 101
  • 10
2
votes
2 answers

Pass arguments from command Line and from function inside shell script

I want know weather it is possible to pass arguments from command line and from the function inside a shell script I know its is possible to pass a argument from command line to shell script using $1 $2 .. But my problem is my shell script needs…
Spencer Bharath
  • 507
  • 2
  • 7
  • 21
2
votes
0 answers

subprocess.call not working from pyCharm

My file structure is: ├── src │   ├── main │   │   ├── costSensitiveClassifier.py └── vowpal.sh | ├── data │   ├── output │   │   ├── cost | | |_______openCostClassifier.dat | | | And within costSensitiveClassifier.py, I essentially am…
Dhruv Ghulati
  • 2,976
  • 3
  • 35
  • 51
2
votes
2 answers

How to save both data and response headers with curl to variables

I've got a sh script with curl request which saves response to the data variable: data=$(curl -X GET -H "Authorization: Bearer dee52f918f769f9734599526a296a0d" -H "Accept: application/json" -H "Cache-Control: no-cache" http://someurl.com/data) But…
Bogdan Timofeev
  • 1,062
  • 3
  • 11
  • 33
2
votes
1 answer

I want to embed a single quote in a string

Usually, in order to embed a quotation mark in a string, \ (backslash) is used. Does a backslash have a different meaning in a Bash script? My code below isn't working: the quotation mark wasn't included, and the following errors were reported:…
SIMONSON92
  • 73
  • 6
2
votes
3 answers

Linux Bash Script - match lower case path in argument with actual filesystem path

I have a linux script that gets an argument passed to it that originates from MSDOS (actually DOSEMU running MS DOS 6.22). The argument that gets passed is case insensitive (as DOS didn't do cases) but of course Linux does. I am trying to get from…
l0ckm4
  • 757
  • 5
  • 17
1 2 3
99
100