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.

0
votes
0answers
37 views

How to create a file of the exact size of a directory (and its files), to hold a FAT32 filesystem?

I'm trying to create a file with the minimum-enough size to contain a FAT32 filesystem, which, in turn, mirrors the contents of a directory (an ESP structure). This is needed to create an UEFI-...
0
votes
0answers
47 views

How to remap a preconfigured keyboard shortcut under linux mint XFCE from a bourne shell script?

TLDR: I am trying to configure a keyboard shortcut from a script (on linux mint XFCE), but the preconfigured key binding gets in the way. I have an installation script that installs apt packages, ...
0
votes
0answers
38 views

How to run a command when any process starts?

I have an sh script to update my wallpaper which uses pscircle in order to display running processes. The script runs every five seconds to update the wallpaper, but I would like it so that the script ...
0
votes
1answer
75 views

How can I use a “here document” in the middle of a pipe?

I am wanting to generate some content using a heredoc as a template: passphrase=$(<passphrase) envsubst <<EOF apiVersion: v1 kind: Secret metadata: name: openshift-passphrase stringData: ...
1
vote
1answer
103 views

Bad number error with Linux float variable value comparison operator condition

I'm trying to test some logic on an Antminer S9 where I get the output of a command and then from that output I grab a specific float value so I can then put this value into a variable and process ...
2
votes
2answers
109 views

Find filenames with uppercase extension

How can I find all the files with their extension in uppercase in 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 files ...
1
vote
2answers
77 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 ...
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
104 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 ...
79
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
171 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
41 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
278 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
191 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
535 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
24 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
53 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
84 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
136 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
2answers
279 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
105 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
134 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
100 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
4k 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
131 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
1answer
359 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 ...
1
vote
1answer
6k 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
849 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
57 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
122 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
89 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
560 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
400 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
3answers
11k 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
147 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
726 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
66 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
211 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
139 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
309 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
50 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
589 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
614 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
3k 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
24 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
603 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
55 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
399 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, ...