Questions tagged [sh]

sh stands for a shell. It is also often used as extension for a shell script.

Filter by
Sorted by
Tagged with
449 votes
6 answers
590k views

How can I resume a stopped job in Linux?

How can I resume a stopped job in Linux? I was using emacs and accidentally hit ctrl-z which blasted me back to the console. I can see it when I type 'jobs' [*****]$ jobs [1]+ Stopped ...
1 vote
1 answer
4k views

How to force a longer `reboot` in Busybox v1.13.3?

reboot appears to make the root file system read-only almost immediately, causing a race condition with one of my processes which tries to write settings out to a file during its approx 1-2 second ...
0 votes
2 answers
4k views

Copy shell configuration from one machine to another?

I've got login to another server where shell configurations are not like I would want. For example I don't see my username and CWD on prompt, and when I press arrow key, instead of giving last entered ...
0 votes
1 answer
29 views

Why directories are not being expanded and some others are not created?

I am using Docker and I am trying to run the following script in the container which uses Alpine Linux and sh as a shell: Note: SCANDISK_MOUNT and SCAN_MOUNT are environment variables defined as var/...
1 vote
0 answers
38 views

Grub script how to remove menuentries

I made a grub script to detect bootable disks and show them on grub menu. It is working but I want to put a rescan button and to make that first I need to remove old menuentries. How can I do? My ...
61 votes
9 answers
297k views

How to display current path in command prompt in linux's sh (not bash)?

I would like to display current path in sh prompt (not bash shell), which currently just shows "#", I tried with introducing this env PS1="$(whoami)@$(hostname):$(pwd)" and set PS1="$(whoami)@$(...
0 votes
3 answers
4k views

Quit loop if a key is pressed

I want to exit the script if any key is pressed. #!/bin/sh while true; do df -h | head sleep 10 clear done Any suggestion?
3 votes
1 answer
3k views

execvp exec format error for shell script on Red Hat Enterprise Linux 6

We have two RHEL 6 systems that are running identical versions of the kernel and glibc (glibc–2.12–1.90.el6_3.6). According to the POSIX standard and the Linux man pages, if the kernel determines that ...
0 votes
1 answer
77 views

sh source permission denied trying to call another script

Can you make a sh script call another script? (Apparently not.) rwb@calleva:~/source$ ls -l total 8 -rwxr--r-- 1 rwb rwb 50 Oct 22 03:38 caller.sh -rwxr--r-- 1 rwb rwb 30 Oct 22 03:36 sourced.sh rwb@...
3 votes
2 answers
3k views

Appending new lines to multiple files

I'm trying to append new lines to multiple files with the following command: find -name *.ovpn -exec sh echo "line to append" >> {} \; before doing this, I ran a different command to make sure ...
0 votes
1 answer
201 views

Bash script vs command line

I have started working on bash scripts. I have just observed a difference between executing a command line and executing the same commands but inside a script. In particular the command line is: for a ...
1 vote
1 answer
69 views

How to create abnormal amount of subdirs?

I want to create 1000x1000x1000x1000x1000, etc. directories, but something like mkdir -p {1..1000}/{1..1000}/{1..1000}/{1..1000} gives to many arguments error or just infinitely eats my RAM... How can ...
1 vote
3 answers
308 views

Using read -r within in-line shell scripting

I have a file that contains a list of absolute paths of several files. I need to move all of the files listed in the file to another directory. Unfortunately, I have to do this using in-line shell ...
11 votes
9 answers
19k views

Why do I sometimes get 'sh: $'\302\211 ... ': command not found' in xterm/sh?

Sometimes when I simply type a valid command like 'find ...', or anything really, I get back the following, which is completely unexpected and confusing (... is command name I type): sh: $'\302\211...'...
0 votes
0 answers
143 views

I have not captured a screenshot using the service

I am using a shell script and I want to run the script automatically when the system is ON/Restart without opening any application. Here is my script.sh file: while sleep 5 do scrot 'myimage.png' -e '...
0 votes
2 answers
2k views

How do I use xargs to pass arguments as $1, $2, $3, ... to an inline script called with sh -c?

I want to pass tokens a b c as arguments of a script that will output a - b - c. If I have a script dummy.sh that does echo "$1 - $2 - $3" and a dummy.dat file containing : a b c d e f and ...
46 votes
3 answers
29k views

Comments in a multi-line bash command

This single-command BASH script file is difficult to understand, so I want to write a comment for each of the actions: echo 'foo' \ | sed 's/d/a/' \ | sed 's/e/b/' \ | sed 's/f/c/' \ > myfile ...
12 votes
1 answer
2k views

What is the second sh in `sh -c 'some shell code' sh`?

Question I encountered the following snippet: sh -c 'some shell code' sh … (where … denotes zero or more additional arguments). I know the first sh is the command. I know sh -c is supposed to ...
10 votes
3 answers
42k views

Bash script: Create a screen session and execute a command in it

I want to write a bash file, which starts a screen session and executes a command inside. The problem is, that it first creates a session and when you manually exited the session it executes the ...
0 votes
1 answer
849 views

Execute Script Via SSH And Disconnect Immediately

The idea is to connect to a remote machine via ssh and execute a shell script without waiting for it to finish. EDIT: The issue was ssh, not nohup.
2 votes
3 answers
2k views

Find filenames with uppercase extension

How can I find all the files with their extension in uppercase recursively in a directory. I've tried : $ find -name "*.[A-Z][A-Z][A-Z]" Seems to work but of course this does not check ...
0 votes
1 answer
6k views

How to use git pull with Jenkins sh steps?

git pull doesn't work with Jenkins for some reason. I've updated some files on my local PC and pushed it to my Github. I can see the changes there. Then I run Jenkins build that has sh commands to ...
14 votes
2 answers
21k views

sh: time command not found

In llvm 3.0 test-suite, I am getting the following error on bash: sh: time command not found The code is: if [ "x$RHOST" = x ] ; then ( sh -c "$ULIMITCMD $TIMEIT -p sh -c '$COMMAND &...
3 votes
1 answer
739 views

Is there a `read -n` equivalent command for Bourne shell?

Is there a way to make my script wait for the user to press any key and then continue without them having to press Enter? I want to make it work in Bourne shell (sh), not Bash.
37 votes
2 answers
9k views

What is wrong with “echo $(stuff)” or “echo `stuff`”?

I used one of the following echo $(stuff) echo `stuff` (where stuff is e.g. pwd or date or something more complicated). Then I was told this syntax is wrong, bad practice, non-elegant, excessive, ...
0 votes
0 answers
168 views

MSYS2 - Change to /bin/sh

How would I switch my default shell from bash to sh in MSYS2? Even just trying to do something as simple as pacman -S sh tries to install bash.
4 votes
1 answer
715 views

/bin/sh is symlinked to bash, but completely different?

If I do ls -l /bin/sh: I get lrwxrwxrwx 1 root root 4 Jan 9 00:01 /bin/sh -> bash However, when I start sh, I get a completely different prompt than I would, my ~/.bashrc isn't sourced, and if I ...
0 votes
1 answer
88 views

Sending FreeBSD script output by email loses format (left aligned and right aligned in one line)

every day I am running a script on my router to check the traffic usage of a specific server. The script is working fine and with this output part of the script, I get following result: #Give output ...
3 votes
1 answer
982 views

Looks like cron spawns a shell which in turn spawns a script; how can I get rid of the intermediate shell?

The OS is CentOS 7. I have a rather basic understanding of crontab and crond. I created a crontab entry using crontab -e: */5 * * * * /root/script.sh > /dev/null 2>&1 The script detects if ...
0 votes
1 answer
208 views

How to copy hidden file names to a text file in unix?

I have several directories which contain hidden empty files. I need the name of these file names themselves, so I need to write the filenames to a txt file. My script looks like this: cd /z/...
0 votes
1 answer
240 views

Windows : launch .sh using environment variable

i'm trying on windows to launch my server from anywhere in my computer (start_server.sh). Launching my file containing those line manually works fine (using GitCMD) (probably not the best, i'm of ...
1 vote
2 answers
61 views

Creating multiple symlinks from a string

I have the following script: #!/bin/bash test="../t1,../t2,../t3" ln -sf "{${test}}" . Above this directory consists of 3 directories: ../ ├── script │   └── test.sh ├── t1 ├── ...
0 votes
1 answer
440 views

Why is sudo able to run in fakeroot?

Take the following snippet: fakeroot -- sudo cat /etc/shadow This will print out the contents of /etc/shadow, but doesn't running sudo in fakeroot ruin it's whole purpose, or am I missing something?
20 votes
9 answers
101k views

How to find length of string in shell

I need to calculate the length of a string using pure sh shell only. What is happening is that /bin/sh is actually a soft link to bash or another shell. Hence ${#STRING} gives the length of string as ...
1 vote
1 answer
2k views

Rsync creates empty folders

I have following directories. My goal is to compare OLD vs NEW directory and save the different files in the DEST directory: OLD/ ...src/ ...src/config.js ...test/ ...test/main.js NEW/ ...src/ ......
user avatar
0 votes
1 answer
138 views

Corrupted Files Delete in Windows [duplicate]

I am preparing a file using shell script and while doing some tests, I added the pause> nul line into my sh file. Then I ran the sh file, but there was a file named nul on the desktop and I can't ...
0 votes
1 answer
563 views

List of JSON strings as command arguments

I've been working with GitLab CI recently to automate some busy tasks, namely auto releasing binaries for version tags. For those who don't know Gitlab CI, it is very straightforward. It pulls the ...
0 votes
2 answers
2k views

"Access Denied" as root

I have connected to my wireless router via telnet as root. It runs on linux kernel and has busybox. / # cat /proc/version Linux version 3.4.110 (root@A23176683) (gcc version 4.7.2 (Buildroot 2013.02) ...
3 votes
1 answer
48k views

"/bin/sh: 1: MY_COMMAND: not found"

Error During docker build -t MY_IMAGE_NAME ., using a Dockerfile for a ROS project, at line RUN source /opt/ros/melodic/setup.bash the following error appeared: => ERROR [stage-2 19/19] RUN ...
4 votes
1 answer
2k views

sh source can't find files

I have an Ubuntu 20.04 installation. I seem unable to source files with sh, which is Ubuntu's default dash. I have a file, lets say build.env, with some environment variables in it like this: build....
0 votes
1 answer
582 views

Start up shell stuck in /bin/sh how to change it back to zsh default at startup

Whenever I start my cli, it keeps starting up in /bin/sh. I've searched various different forms and none so far have worked for my issue. I also tried various options like chsh (1) <--- this only ...
0 votes
1 answer
64 views

How to run drkspider.sh on windows 10

I have downloaded DRKSpiderJava v0.83 but I cannot run the file "drkspider.sh" on Windows 10. I tried with cmd, CYG, bash but don't know why cannot open it. Maybe I am doing something wrong?
21 votes
2 answers
19k views

Is there a way to "source" a sh script from the fish shell?

I like to put many of my environment variable definitions in the .profile script. If I am using a POSIX-compatible interactive shell like bash, I can use the source command to re-export the ...
0 votes
1 answer
134 views

bash vs zsh man page search feature differs

I'm switching to zsh from bash, but I just realized that when I'm in a man page in bash and use / to search, I can use the hyphen - like this: /-V and all -V occurences will be found, as expected. But ...
0 votes
2 answers
237 views

Some standard commands freeze on remote machine

I'm using a remote machine (ssh connection), and some commands suddenly stopped working. By that I mean that I enter them and nothing happens: they just kind of freeze, without any output and without ...
0 votes
1 answer
2k views

how to run multiple shell scripts one by one in single go using another shell script

Dear experts i have a small problem...i am trying to run multiple shell scripts having same extension(.sh) in one go, which are present inside a directory. In so far i wrote a common script like as ...
24 votes
3 answers
9k views

How is install -c different from cp

What is the difference between install -c and cp? Most installations tend to use install -c, but from the man page it doesn't sound like it does anything different than cp (except maybe the ability to ...
1 vote
0 answers
41 views

FFMPEG Bash Script incorrectly using cover metadata instead of images

I'm trying to run a script that that is meant to convert a folder of images and a folder of audio into videos however it's pulling the metadata of the album art instead. Looking for a correction ...
0 votes
1 answer
154 views

Why does the value of $HOME vary between Ubuntu 18.04 & 20.04 in a script using sudo

On Windows 10 v1909, I am using WSL (Ubuntu 18.04 & 20.04: 4.4.0-18362-Microsoft x86_64 GNU/Linux) and I noticed the value of $HOME within an arbitrary script varies between Ubuntu 18.04 and 20.04 ...
0 votes
1 answer
504 views

Bash script which logs log in/log out event of users in real-time

I'm curious about bash script, which will write information to the file once any user will log in/log out to the system in real-time? Can I check it by filtering of commands from ps ps -eo user,...

1
2 3 4 5