Questions tagged [bourne-shell]

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

Filter by
Sorted by
Tagged with
1
vote
1answer
25 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 ...
-9
votes
0answers
38 views

3 question Guys !! Bourne Again Shell :( [on hold]

Which Control Structure did you use in the script you created in the previous step? Which prompt variable is used with the select command structure I want to name this script as 'lab10-1' and include '...
3
votes
0answers
44 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 ...
1
vote
1answer
612 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?
17
votes
5answers
2k 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 ...
0
votes
2answers
1k 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. ...
1
vote
2answers
933 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 ...
0
votes
0answers
80 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 ...
8
votes
2answers
1k 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 ...
0
votes
1answer
152 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 ...
1
vote
1answer
280 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 ...
2
votes
1answer
828 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 ...
0
votes
3answers
424 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 ...
0
votes
1answer
138 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 ...
12
votes
3answers
1k 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 ...
1
vote
1answer
285 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 ...
0
votes
1answer
386 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 ...
1
vote
1answer
339 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 ...
-1
votes
1answer
98 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 ...
2
votes
2answers
111 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, ...
0
votes
2answers
83 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 ...
3
votes
1answer
588 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/...
4
votes
2answers
483 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 ...
0
votes
1answer
3k 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 ...
14
votes
4answers
30k 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 can try change directory if cd fails to do so. Would you like to add this feature?...
1
vote
1answer
87 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 ...
1
vote
2answers
457 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 ...
2
votes
0answers
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 ...
4
votes
1answer
123 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 ...
1
vote
1answer
80 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 ...
1
vote
3answers
92 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 ...
4
votes
1answer
2k 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/...
25
votes
4answers
35k views

Arrays in Unix Bourne Shell

I am trying to use arrays in Bourne shell (/bin/sh). I found that the way to initialize array elements is: arr=(1 2 3) But it is encountering an error: syntax error at line 8: `arr=' unexpected ...
2
votes
0answers
119 views

What privileges do I have (find out within bourne shell script) [closed]

I am hacking away on a remote helper for git. The script is in bourne shell. I wanted to create some temporary directory in the home dir. For some reason I get permission denied. From my shell ...
19
votes
3answers
1k 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 this ...
11
votes
1answer
6k views

IFS null is not the same as unset IFS?

I read a great question on here called Understanding IFS. I was surprised because the answers and comments quote POSIX which states that IFS= is not the same as unsetting IFS. If you unset IFS, ...
5
votes
2answers
6k views

bourne shell if [ -e $directory/file.$suffix ]

#!/bin/sh CONFIG_DIR="/var/opt/SUNWldm/" read option if [ $option -eq 9 ]; then ret=1 elif [ -e ${CONFIG_DIR}file.xml.${option} ]; then echo "TRUE" fi I have the above code in a while ...