Stack Exchange Network

Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [sh]

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

1
vote
2answers
51 views

Is it POSIX-compliant to use a shell function in a pipeline?

Is it possible to use a shell function in a pipeline? Say I had a function that acted like grep, called mygrep. Is there any way, using only POSIX shell features, to be able to invoke mygrep like ...
0
votes
0answers
22 views

Audio Issues With FFmpeg Script

I have a script to convert all files in a dir using ffmpeg. When I convert a file, it has audio distortion. If I convert the same file using something like handbreak there are no issue. Any ideas what ...
30
votes
2answers
4k 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, a bad practice, non-elegant, excessive, ...
2
votes
1answer
98 views

Grep regex result not as expected?

Using FreeBSD 11.1: #!/bin/sh if printf 'abcde.fgh' | grep -iEq '^[^][$^*_-]'; then echo "test 1 success" else echo "test 1 fail" fi echo if printf 'abcde.fgh' | grep -iEq '^[^][.$^*_-]'; ...
0
votes
1answer
61 views

Raspberry Pi headless, my if [[ file1 -nt file 2 ]] that thinks the two files have the same modified date

So I have a player script "player.sh" and an updater script "updater.sh". player.sh plays any mp3 file in /home/filepath/ using a wild card *.mp3, this works as expected. what I want is for the ...
78
votes
1answer
6k views

Is redirection with `>>` equivalent to `>` when target file doesn't yet exist?

Consider a shell like Bash or sh. The basic difference between > and >> manifests itself in a case when the target file exists: > truncates the file to zero size, then writes; >> ...
0
votes
0answers
97 views

SSH : “Connection reset” for one of my LXC's

I've been stuck for a while about my ssh connection to one of my LXC's. Indeed, when I connect in ssh to my other LXC, everything works. However, one does not want to connect and displays this error: ...
0
votes
1answer
36 views

Bash modifying text between marked lines

I have a file with more than 8000 rows. File is divided into sections, each section is labeled with text like ##C, ##T,##N. I have to modify some rows in the file. I used command SED to mark lines ...
0
votes
3answers
76 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?
1
vote
2answers
110 views

Get intermediate nodes using ping

I need to get intermediate nodes when requesting the route through ping. I can get the intermediate routes through traceroute url, but in the server there's a problem I cannot use traceroute. I ...
0
votes
1answer
146 views

using xargs pass arguments to sub shell with pipe

I want to rename a number of files. I think I can use xargs to do it. find ./ -name "upload.log-*" ./upload.log-20180622.gz-20180624.gz-20180626.gz ./upload.log-20180624.gz-20180626.gz ./upload.log-...
1
vote
1answer
21 views

Handle filename with blank in shellscript

These are my folder structure. [set symbolic links here] /links/ [entity] /data/a 1/ #(folder name has blank) /data/b 1/ /data/c 1/ /data/d 1/ . . . I want to made symbolic link for each ...
0
votes
0answers
44 views

free -m and uptime commands sometimes not returning result

I have http://trafikito.com agent running on several servers and what it does - it takes commands to execute, executes and sends outputs to Trafikito dashboard to display stuff on charts. I have 10 ...
2
votes
2answers
81 views

Shell script get email notification when the server is connected to internet

I want to check if a server has connected to the internet or not. I have tried following script unsuccessfully, which runs every 5 min and checks and sends an email if it is connected to internet. ...
1
vote
1answer
84 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
1answer
94 views

Command After Semicolon Not Executed in Crontab?

Here is my crontab: 42 17 * * 1-5 /bin/pkill -f 'MyExecutable.exe' ; touch /tmp/here.log And according to /var/log/cron, it did run: May 22 17:42:01 server1 CROND[326732]: (myuser) CMD (/bin/pkill ...
0
votes
2answers
91 views

sh syntax to handle zero files matching a wildcard, as well as more?

I want to write a /bin/sh shell script which will handle any files matching a wildcard. It's easy to handle 1 or more matching files. However, I'm finding it awkward to handle the case of 0 matching ...
0
votes
0answers
76 views

Openvas ' Failed to read response' in bash script

Im a beginner with bash script. I have an OpenVAS bash script that is trying to create a target, retrieve the target ID then create a task and retrieve the task ID. #!/bin/bash Target_return=$(omp --...
0
votes
0answers
97 views

Running IPTABLES commands on boot (on locked down, IoT device)

I am using a cell modem/router that is running a vendor custom distribution of Linux kernel 3.12.70. I'd like to add custom iptables rules, but they keep being deleted on reboot. I've tried https://...
0
votes
1answer
2k 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 ...
5
votes
1answer
116 views

Ssh X11 forwarding messes up with default shell

I have a bash specific code in my bash profile: $ cat ~/.bash_profile #!/usr/bin/env bash echo "SHELL: $SHELL" function printfiles() { while IFS='' read -r _file || [[ -n "$_file" ]]; do echo ...
0
votes
0answers
24 views

POSIX compliant way of saving content of regex capture groups in variables

I am building a sh script that needs to be as much POSIX compliant as possible and I want to extract data from system files, I wrote regular expressions to do this but I can't find how to put the ...
0
votes
1answer
271 views

Watch + pipe + multiple arguments

I have a command diff -y <(xxd FILE) <(xxd FILE_) | colordiff and i want to put it into watch routine. Something like that: watch -n 0,1 'diff -y <(xxd FILE) <(xxd FILE_)' But i have an ...
0
votes
1answer
4k views

Associating linux shell (.sh) scripts on Windows 10 to Bash or WSL [duplicate]

If you ever tried to run an .sh linux script on Windows 10 by double-clicking it, after assigning it to bash.exe (Ubuntu Bash for Windows 10) by default, you most likely noticed it wouldn't open. Why ...
0
votes
1answer
697 views

Conky and Wunderground Weather

I am editing my question for clarification... I am sorry for any confusion... The Conky syntax has changed with the latest version (I assumed users of the latest version of Conky was aware of that). ...
0
votes
0answers
54 views

screen command called from within a script, within a “su -c” command creates files on root directory

I'm executing this script from user root in directory "/": su -c "sh /home/bob/start_server.sh" bob and "start_server.sh" contains screen -d -m -S serverscreen mono startserver.exe However all the ...
1
vote
1answer
80 views

IF block statement in inside an execlineb script

I have a Docker Container based on Alpine which runs S6 Overlay to manage two services inside it (a music DB, and a web interface to manage it). The problem is that the second service is optional, and ...
0
votes
1answer
80 views

bash .sh script looping instead of ending/exiting

I'm writing my very first bash script. Everytime I've run it to make sure it works, everything works exactly as I'd like it to with the exception of the done command at the very end. Instead it ...
4
votes
2answers
420 views

GNU Parallel - global variables and function

I have this script: GLOBAL_VAR="some global value" function test { echo $1 echo ${GLOBAL_VAR} } export -f test parallel --jobs 5 --linebuffer test ::: "${files[@]}" How can I have $...
0
votes
1answer
357 views

sh file is not running on nginx web server

I am using nginx web server in openwrt and made page using shell script and html. The issue is shell commands are not running but html tags are running. Below is my code. #!/bin/sh echo "Content-...
1
vote
2answers
7k views

How to use source command in shell script

I would like to use source command in shell script. What I have done is like this below, in start.sh source ~/tensorflow/bin/activate then in command line run this script. $sh start.sh However ...
1
vote
1answer
139 views

find file containing a function

I would like to know a way to get the file that contains a function that is accessible because it's been sourced in shell. For Bash and ZSH. For example when I want to find out the source of function ...
0
votes
1answer
658 views

How to schedule a bash script to run at a certain time

I'm using the code #!/bin/bash while :; do ffmpeg -re -i "input" output.mp4 done to loop a .sh file. Is there a way to edit this so it starts at 5pm CST every day and then stops at 9pm CST? ...
1
vote
0answers
63 views

Bash script - Finding files and manipulating paths

So I'm attempting to write a script that achieves the following: Reads file UID from a text file Searches for file location based on the UID Copies the file, including it's path structure to a new ...
1
vote
1answer
165 views

Use section sign § as cut delimiter

I thought this would be pretty straight forward echo "1§2" | cut -d § -f 2 should give "2", right? But whatever I try echo "1§2" | cut -d § -f 2 echo "1§2" | cut -d \§ -f 2 echo "1§2" | cut -d "§" ...
2
votes
0answers
127 views

AIX sudo rootsh

I'm allowed to do: sudo /usr/bin/rootsh -i -u user Additionally I want do something like: echo 'date' | sudo /usr/bin/rootsh -i -u user Here I get the answer: no tty/pty on stdin: Not a ...
1
vote
2answers
264 views

Method to ls and awk directory contents into a shell variable

I'm struggling to find some way to express this in some other fashion that will yield the appropriate output: var="$(ls /var/run/ | grep searchterm | awk {'NR == 2'})" I've seen on places like ...
0
votes
0answers
48 views

Problems in customizing the macOS menu bar with MenuSystemUIServer

In my menu bar, I'd like to hide TimeMachine, Volume, Battery, User, Clock and show just Bluetooth, and Airport. I tried to customize it with an sh script: for domain in ~/Library/Preferences/ByHost/...
3
votes
2answers
554 views

scp and line break in a shell script

I have an .sh file, containing a command, which copies a file from remote server to a particular directory, preserving original filename, and the second line is just a comment: scp (host):~/filename....
26
votes
4answers
4k views

What does % do in Linux shell strings?

In Linux shell, what does % do, as in: for file in *.png.jpg; do mv "$file" "${file%.png.jpg}.jpg" done
11
votes
1answer
611 views

Why doesn't this softlink work as expected?

bash4.3 # pwd /bin bash4.3 # ll sh lrwxrwxrwx. 1 root root 4 May 17 22:22 sh -> bash bash4.3 # ll bash -rwxr-xr-x. 1 root root 1072056 May 17 22:22 bash bash4.3 # bash bash4.3 # ...
0
votes
2answers
2k views

Run Script on OSX Automatically

How can I run a script I made on my mac automatically. It needs to run once a day. Because it requires rsync the mac needs to be connected to the internet and I have realised when it is sleeping wifi ...
0
votes
1answer
23 views

Reset Cache using bash

I'm trying to automate a .sh file to run every time before Chrome opens, here's what I want to do. rm -rf /home/pi/.config/chromium tar -cvf reseterfiles.tgz /home/pi/.config/ The zipped ...
1
vote
2answers
491 views

How to transparently substitute sha1sum for shasum in sh shell?

I have a test that needs to run on multiple platforms. On all other platforms, the test uses sha1sum, but on my Mac OSX El Capitan, there is no such program installed, but shasum works fine as a ...
0
votes
0answers
53 views

Startup script unexpected results

I'm experimenting with a small script to setup my webserver on Vultr. This is a "Startup script" that is used by Vultr on the background after deploying a new machine for me. If I run manually with ...
0
votes
0answers
353 views

sh command not found on Windows 10

I'm trying to install devkit using the command npm install -g devkit. It makes a loading bar which goes on for a few minutes then gives an error, firstly saying that the sh command can't be found, ...
0
votes
0answers
171 views

How to make ConEmu execute .sh in the same window with Git for Windows?

I'm using ConEmu on Windows with Git for Windows installed. When I try to execute an .sh script, the software starts an instance of Windows' default console and executes the script there. How can I ...
4
votes
1answer
110 views

Redirecting display linux

from a sh shell, I am running a script calling a Software that requires opening a Gui. It ends up with a flashing window each time the call is run. I tried to unset the DISPLAY environment variable ...
-1
votes
2answers
643 views

what does “exec 5>>foobar.txt” do?

What does the shell command exec 5>>foobar.txt do? I can't google it for obvious reasons, and otherwise not sure where to start looking.
0
votes
1answer
44 views

Piping stdout from a command to stdin of two commands in sh

tee [using >()] command is not working because it is not supported in sh (bourne shell). What I am trying to achieve is sending the output of "ifconfig -a" to two different commands. This is my ...