Skip to main content

Questions tagged [bourne-shell]

The Bourne shell is a historical implementation of /bin/sh

Filter by
Sorted by
Tagged with
4 votes
2 answers
970 views

Does any implementation of `which` output "no" when executable cannot be found?

I am reading the source code of the Maven wrapper written for the Bourne shell. I came across these lines: if [ -z "$JAVA_HOME" ]; then javaExecutable="$(which javac)" if [ ...
Stefan van den Akker's user avatar
0 votes
2 answers
425 views

Is there a syntax for a "for" loop over words or lines in a variable, that will work unmofdified in both bourne shell and zsh?

I have a variable that contains a list of strings, one per line, to be looped over in a for...in...do...done command. I move regularly between bourne shell and zsh. As far as I can understand it, zsh ...
Stilez's user avatar
  • 1,271
2 votes
2 answers
869 views

What is the difference between .shrc and .profile?

I want to try out Bourne shell on FreeBSD so I am starting to set it up for my use. In .shrc, I set my prompt, enabled vi mode, set some aliases, and exported some variables. However, I see that ....
Vladimir's user avatar
  • 189
0 votes
1 answer
112 views

How was a shell like when operating systems didn't had a GUI? [closed]

I understand the concepts of terminal, console, shell and their differences. I know a shell today is an interpreter that communicates with the OS kernel to perform some actions and does it through ...
GerardoAGL96's user avatar
1 vote
3 answers
206 views

export command behaviour in bash vs bourne shell

bash v3.2 (though I think holds for newer versions too): In section 3.7.4 Environment, the docs say: On invocation, the shell scans its own environment and creates a parameter for each name found, ...
Ben Ldr's user avatar
  • 13
7 votes
1 answer
1k views

Does Bourne Shell have a regex validator?

I am on a closed network (i.e. no connectivity to the internet). I have a bourne shell script that asks for the user to enter a regular expression for use with grep -P. Generally speaking, I like to ...
Scottie H's user avatar
  • 674
3 votes
1 answer
833 views

What is "length" of a string in Bourne shell compatibles' `${#string}`?

Arising from this discussion: When I have (zsh 5.8, bash 5.1.0) var="ASCII" echo "${var} has the length ${#var}, and is $(printf "%s" "$var"| wc -c) bytes long" ...
Marcus Müller's user avatar
-3 votes
1 answer
60 views

What is extension and execution command for following [duplicate]

What is extension & execution command for following file formats - Bourne Shell, Korn Shell, Bourne Again Shell, POXIS shell & TENEX/TOPS C Shell. Like normal bash file can be created with '....
Gaurav's user avatar
  • 1
4 votes
4 answers
446 views

Getting search results for Bourne shell [closed]

So, there are many types of shells in Linux... Different Types of Shells in Linux The Bourne Shell (sh) ... The GNU Bourne-Again Shell (bash) ... The C Shell (csh) ... The Korn Shell (ksh) ... The Z ...
pgr's user avatar
  • 151
0 votes
1 answer
204 views

Help with a deciphering command with telnetd in it

Help with deciphering commands [ $1 -ge 20 ] && telnetd -p 233 -l /bin/sh I know /bin/sh is a Bourne shell and telnetd is a telnet daemon but I'm not sure how they work together. I think ...
Rick T's user avatar
  • 357
0 votes
2 answers
402 views

Sharing environment variables between zsh and bourne shell (for crontab)

I set JAVA_HOME in .zshrc: export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64/jre/ which is fine for interactive programs. But I have JVM programs running via cron, which uses Bourne shell. The ...
Sridhar Sarnobat's user avatar
1 vote
2 answers
570 views

syntax error on case statement after ssh session

#!/bin/sh echo -n "Enter the raspberry ip address you want to connect:" read Rasp_id sshpass -p "the@Donut" ssh -t -X -oStrictHostKeyChecking=no pi@$Rasp_id << E2 ...
TensorFlowGuan's user avatar
0 votes
2 answers
6k views

How to get into python environment and run some python commands and return to normal terminal using shell script

Sorry about the title it may not be clear. Here is the complete explanation of my doubt. I am writing the below shell script and expecting the mentioned output. #!/bin/bash python3 print("Hello ...
Rakesh Nara 10's user avatar
-1 votes
2 answers
2k views

How to insert \n within a string

I'm generating a private key, this key is for demonstrable purposes only: $ openssl genrsa -----BEGIN RSA PRIVATE KEY----- MIIEogIBAAKCAQEAvB8fZFRS83Kztend5KO9cnWXaqLWot0qLDeLcS8ly718FUdm ...
user422813's user avatar
1 vote
1 answer
405 views

Why is Bourne shell considered obsolete? [closed]

Is the relation between Bourne shell and Bash similar to that of C and C++(if so it would signify that both have their place as a shell)? Whenever I read something about shells it always says that ...
john's user avatar
  • 33
1 vote
3 answers
1k views

Reading multiple lines in Bourne Shell

I'm trying to read two lines into two variables. In Bash I would use something like this: cat << EOF > myfile line1 line2 EOF cat myfile | { read firstline echo $firstline # "line1" in ...
jasper's user avatar
  • 121
1 vote
3 answers
1k views

Need Improvement on Script Which Continuously Tests Website

Need improvement on a script which continuously tests website. It's currently been used the following script, but it is giving a large amount of failing emails, while website is still up: #!/bin/...
Baraujo85's user avatar
  • 698
9 votes
1 answer
1k views

Trying to write a shell script that keeps testing a server remotely, but it keeps falling in else statement when I logout

Trying here to write a shell script that keeps testing my server and email me when it becomes down. The problem is that when I logout from ssh connection, despite running it with & at the end of ...
Baraujo85's user avatar
  • 698
1 vote
1 answer
785 views

Passing --out-format=FMT argument to rsync from Bourne shell script

I'm trying to execute rsync from a Bourne shell script (read: Bash extensions not available) and after lots of searching, single/double quotes combinations, escapes, etc, I wasn't able to correctly ...
cesss's user avatar
  • 318
1 vote
1 answer
49 views

Mirror-like of source code tree applying beautifier to modified files only

I keep two copies of the same source code tree: One is the "working copy", and the other is the "stored copy". When I finish editing the "working copy", I refresh the "stored copy" with rsync (only ...
cesss's user avatar
  • 318
2 votes
0 answers
82 views

How did Bourne shell solve missing teletype keys problem?

I've learned recently from DigitalRoss's answer that certain teletypes such as ASR-33 lacked certain keys; for instance |. For that purpose in C there exist trigraph operators that can be substituted ...
Sergiy Kolodyazhnyy's user avatar
1 vote
1 answer
856 views

What is the etymology of $PS1? [closed]

What do the letters PS stand for in $PS1? Is it actually "Prompt String"? Where did $PS1 first appear?
Tom Hale's user avatar
  • 31.2k
20 votes
5 answers
20k views

Is there an "in" operator in bash/bourne?

I’m looking for an “in” operator that works something like this: if [ "$1" in ("cat","dog","mouse") ]; then echo "dollar 1 is either a cat or a dog or a mouse" fi It's obviously a much shorter ...
mrjayviper's user avatar
  • 2,081
1 vote
2 answers
4k views

How to use switch case in my case?

My problem definition is : 1.Write a Bourn shell script dTOe which takes as an input any number between 0 and 999 and prints the English value for this number. I am struggling with above problem. ...
GideokSeong's user avatar
3 votes
2 answers
5k views

Checking for root user in sh and bash [duplicate]

I am attempting to write a script that automates the installation of ports/packages on new FreeBSD installs. To do this, the user who executes the script must be root. The system is "supposed" to be ...
Allan's user avatar
  • 1,060
0 votes
0 answers
151 views

launching bourne shell script with $USR env

I am running a bourne shell script from a service script. When I check $env from my #!/bin/sh script started by script the user is ROOT and path is [/] Is there a way to pass the env of the logged ...
user1610950's user avatar
29 votes
3 answers
14k views

How can I create an arithmetic loop in a POSIX shell script?

I know how to create an arithmetic for loop in bash. How can one do an equivalent loop in a POSIX shell script? As there are various ways of achieving the same goal, feel free to add your own answer ...
Vlastimil Burián's user avatar
0 votes
1 answer
675 views

sort files greater than 1000 bytes in descending order

I can sort the files either in descending order (of any size) or list all files greater than 1000 bytes but don't know how to sort files greater than 1000 bytes in a user specified directory. List ...
Mayank Kumar's user avatar
1 vote
1 answer
416 views

Automating Certbot for OSX Server error in get_cert.sh script [closed]

I am currently facing a problem with my Mac OS-X El Capitan machine when running certbot (or basically letsencrypt). My machine is a mac mini, that is supposedly running an MDM solution with ...
joke's user avatar
  • 31
2 votes
1 answer
2k views

Solaris /bin/sh sourcing a file behaves differently than executing a file. Why?

I have a bash script which will be called by /bin/sh on a Solaris machine. When I run the script as /bin/sh ./solarisSh, it works. When I source the same script, it fails. I know bash and Bourne ...
Erik Bennett's user avatar
2 votes
3 answers
2k views

How do I convert a relative to an absolute path, portably and robustly?

Suppose I'm running bash on a Unix-ish system - not necessarily Linux and not necessarily very new; and it may not have every bit of software I'd like. Now, I have a relative path for which I want to ...
einpoklum's user avatar
  • 9,653
0 votes
1 answer
500 views

How to sort by day of the week? [duplicate]

I have a project I am working on that is very similar to the one below i just found so i don't want to make a hassle for anyone to read again, however in the question I found the top answer user had ...
Ali Soujod's user avatar
15 votes
3 answers
3k views

Is "${PS1-}" valid syntax and how does it differ from plain "$PS1"?

I am looking at a script that has: if [ "${PS1-}" ]; then That trailing - bugs me a bit because it doesn't seem to Posix or Bash standard syntax. It this some arcane syntax that has been around ...
Gregor's user avatar
  • 1,339
1 vote
1 answer
999 views

Bourne shell: what does it execute on interactive, non-login?

I ask in that way, because according to https://unix.stackexchange.com/a/46856/84749, when I start screen it's an "interactive, non-login" I'm doing. What's actually happening is I'm logging into a ...
Opux's user avatar
  • 217
-1 votes
1 answer
800 views

When apt-get upgrade or apt upgrade is run from shell script and "dialog" is invoked, input hangs

After su-ing to root and running directly from the command line "apt upgrade", some packages upgrades result in a dialog -- white on blue text, with red block highlight for option selected with tab ...
J G Miller's user avatar
1 vote
1 answer
501 views

Determine how bash or sh was called

From a bash or sh shell, how can I determine if it was called with the bash or sh command, a login shell, an xterm, and, in the case of the former, how was that called? For example, if I call bash ...
Will's user avatar
  • 811
-1 votes
1 answer
112 views

Creating alias failing in bashrc using function method

I am trying to create alias in bashrc using function method as I need to pass argument while executing. Here i have created alias. login-lnx1 () { 'ssh -o UserKnownHostsFile=/dev/null -o ...
hafiz's user avatar
  • 1
4 votes
2 answers
891 views

Is it possible to "protect" an IFS character from field splitting?

In a POSIX sh, or in the Bourne shell (as in Solaris 10's /bin/sh), is it possible to have something like: a='some var with spaces and a special space' printf "%s\n" $a And, with the default IFS, ...
muru's user avatar
  • 73.9k
1 vote
2 answers
289 views

find exiting on 1st found and return code

I would like to use find on a directory structure to exit if at least one file exists with a target condition, because this will lead to a failure of the rest of a shell script. Since this shell ...
dan's user avatar
  • 933
3 votes
1 answer
1k views

Getting script's real absolute path in /bin/sh

I'm looking for a way to get the real absolute path to the current /bin/sh script. It should work for situations like this one: /path/to/symlink/in/PATH/somescript -> ../../Package/current/...
kjo's user avatar
  • 15.6k
4 votes
2 answers
581 views

SH: How to make vars from one script available in the main script?

I have two scripts that need to run and both require the same variables set the same way. As a result I figured I'd break the setting of the variables out into a separate script. However, I can't seem ...
Doug's user avatar
  • 439
1 vote
1 answer
5k views

syntax error: invalid arithmetic operator (error token is ".c")

I am trying to test if file "file1.c" is present in the current working directory, what am I doing wrong with my test command? I thought I understood this command, am I doing something wrong for the ...
Andrew M's user avatar
32 votes
4 answers
77k views

How to break a long string into multiple lines in the prompt of read -p within the source code?

I am writing an installation script that will be run as /bin/sh. There is a line prompting for a file: read -p "goat may try to change directory if cd fails to do so. Would you like to add this ...
Mateusz Piotrowski's user avatar
1 vote
1 answer
186 views

What does a ">|"-redirection ("greater-pipe"-redirection) mean? [duplicate]

What does the >|-redirection in bash do? I just found out, that echo text >| somefile creates the file somefile (if not existing yet), and fills it with text. Similar as echo text > somefile ...
Golar Ramblar's user avatar
1 vote
2 answers
643 views

Bourne Shell to CShell

This works fine: #!/bin/sh ALTER="$1" NAME="$2" for pr in $(pgrep $NAME); do elapse=$(ps -o etime= -p $pr) [ "${elapse%:*}" -gt "$ALTER" ] && echo $pr done But if I try to switch ...
JuM's user avatar
  • 47
2 votes
0 answers
41 views

When would you use $* instead of $@ in Bourne shells? [duplicate]

In Bourne shell and its offshoots like Bash, I believe the only difference between $* and $@ is that $@ expands in double quotes so that each argument ends up as a single word even if it contained ...
user129758's user avatar
4 votes
1 answer
145 views

"$@" expansion for user defined variables

I'm trying to get a (bourne shell) variable to expand like "$@" so it produces multiple words with some having preserved spaces. I've tried defining the variable in many different ways but still can't ...
user126144's user avatar
1 vote
1 answer
165 views

Bourne shell: ignoring certain kinds of stdin

I have a program that is currently working, but I need to modify it to ignore some stdin that is not fitting for its correct function. Right now, to run the program: printf "1\n3\n5\n" | sh prog The ...
user3295674's user avatar
3 votes
3 answers
221 views

Bourne shell: trailing `-` operator in parameter substitution

I'm reading a shell script for adding a progress bar to certain processes (found here). I'm having trouble understanding this (optional) line: #BAR_EXT=${BAR_EXT-} The comment says that this will ...
wubzy's user avatar
  • 33
4 votes
1 answer
3k views

Variable scope in while-read-loop on Solaris

Could someone please explain to me why my while loop seems to have an internal scope? I've seen multiple explanations online but they all have to do with pipes. My code has none. The code: #!/bin/...
Joel Cochran's user avatar