Questions tagged [shell]

The shell is Unix's command-line interface. You can type commands in a shell interactively, or write scripts to automate tasks. Use this tag for questions applying to /bin/sh and most compatible shells (ash, bash, ksh, zsh, …). For shell scripts with errors, please check them in http://shellcheck.net before posting here.

Filter by
Sorted by
Tagged with
1
vote
2answers
47 views

find command with variable in it

I want to do this: readarray var1 < <(find "/path/to/dir" \( $var2 \) | sort) echo $var2 user@domain:~# -name "*.avi" -o -name "*.mkv" Unfortunately, my script does not work. Please, tell me ...
3
votes
3answers
633 views

What does `[$'\r\n']` mean?

I regularly use the expression line=${line//[$'\r\n']}. But what does [$'\r\n'] mean? I know it removes the '\r\n' characters but how does it do this? Does it remove the instances of both characters ...
-1
votes
1answer
40 views

How to count number of files in a directory that are over a certain file size [duplicate]

Is there a way to count how many files in a specific directory are over some file size? Say, 100 MB?
2
votes
2answers
75 views

Read everything that's displayed in the terminal

I am creating a terminal application that writes stuff to the terminal. And in order to test it, I really should test what's actually displayed in the terminal. Is there a way to read the data that's ...
0
votes
0answers
15 views

With netcat how to safely open an external port to the Internet

I have found the perfect solution to write scripts which send files across machines over the Internet using netcat. On the machine receiving files I do nc -l -p 1234 -k and then on the machines ...
0
votes
0answers
27 views

Getting error while running the shell script

CURRTIME=$(perl -e ' print time(), "\n"') FILETIME=$(cat timestamp.txt ) TIMEDIFF=$(($CURRTIME - $FILETIME)) I need to add 1 second to FILETIME variable, even if there is no entry in timestamp.txt, ...
1
vote
2answers
57 views

How can I stop an inlined background process when my main script stops?

In a shell script, I do the following: #!/bin/sh while true; do <some application>; sleep 1; done & ... rest of the scrip ... This guarantees that the application is always running, as ...
0
votes
2answers
74 views

Why does the command 'source' have that name?

I wonder why a command that executes commands from a file in the current shell is named source. I can't see a relation between run commands in the current shell and the meaning of the english word ...
0
votes
2answers
96 views

Bash command to check if multiple files exist in the directory

Wanted to check if there are multiple files with the same prefix exist in that directory. here directory --> WORK_DIR and file prefix -->SRC_FILE_EXT i currently have the script like this: if [ -s $...
0
votes
1answer
37 views

default variable in bash 3 or bash 4 [duplicate]

I have this: local v="${name-$tag}" # default is name, tag is backup except it doesn't work if name is empty. So the long-way to do this would be: local v="$name"; if [[ -z "$v" ]]; then v = "$...
-1
votes
2answers
37 views

Weird behavior when looping over files in folder

No idea what's happening here. I am on Bash 3.2 on a Mac. I have: ores_resource(){ for f in "$(cd "$HOME/.oresoftware/bash" && find . -type f)"; do f="${f:2}" echo "my file $f"...
1
vote
2answers
61 views

sh: is there a command to interactively edit the PWD?

I'm looking for a command that invokes readline or similar, primed with the current $PWD, to let the user edit the current directory, then cd to the edited value. E.g. > cd ~/a/b/c/d > pwd > ...
0
votes
2answers
28 views

Filter out difference from two files into seprate files

I have 2 files for comparison. I want Transfer the different records from both the files in two separate file. File1 A|B|C|D 1|2|3|5 E|F|G|H File2 A|B|C|D 1|2|3|4 E|F|I|H Output Like... ...
-1
votes
1answer
55 views

how to increment counter value in different functions in shell script

i have 5 functions ..if one function works count value should be incremented and that value should be given to next function count=1 function1() { count++ } function2(){ count++ }
0
votes
1answer
31 views

How to interchange or insert the characters between the arguments in Linux?

We migrated apps from Solaris to Linux , and email functionality (mutt) behavior differs in Linux when attachment (-a) option is used. so instead of modifying all our shell scripts we are planning to ...
-3
votes
2answers
35 views

I want to write a condition where condition should paas only if variable (grp_no)contains either “full” or value between 1-64

Below is the condition: exitprocess() { case $1 in "0") echo "Error in connecting DB or Executing DML statements" exit 0 ;; "1") echo "Group number should be either FULL or between ...
0
votes
1answer
50 views

When is the kernel-mode TTY emulation (Linux console) used instead of user-mode TTY emulation (PTY)?

Having read this canonical article on TTYs, I'm not sure when kernel-mode TTY emulation (Linux console) is used instead of user-mode TTY emulation (e.g. xterm). Normally, I'm always using gnome-...
-1
votes
1answer
51 views

SSH to ubuntu server doesn't give me a login shell [closed]

After manually build bash 5.3, and set environment variable PATH to /tools/bash, when I ssh to server, it uses my build bash and gives me a non-login shell. I'm confused what was happen in this ...
1
vote
1answer
91 views

Unable to alias !! (double exclamation) in bash [duplicate]

I was trying to create an alias in bash alias r='!!' My idea was to create a simple alias r to run the previous command instead of using !! (double exclamation) to run the most recent command as it ...
0
votes
1answer
112 views

Terminal long line wrapping [duplicate]

I got a small issue with line wrapping on a custom linux and I'm not sure where this is set. When on serial console or using SSH login i get the following: Cursor at start of line [user@myhost ~]$ ...
0
votes
2answers
145 views

How to sudo + exec?

I need to use sudo to run process as a different user. But how to use sudo with exec like: sudo -u www-data exec php -r 'sleep(2); echo 5;' to replace the sudo process? Why and requirements? ...
1
vote
1answer
62 views

How to read a file with two columns into a script so that each line read as two variables

I have a file that has two columns like such. cat test.txt 100 2007 FFF 1993 7E7 1994 4BB 1995 I need to input each of the lines into a script, and have the two columns assigned as separate ...
0
votes
2answers
41 views

How to dynamically look up shell variable name [duplicate]

I have this situation: zmx_stderr='\033[1;35m' zmx_stdout='\033[1;36m' tag='foobar' tailing(){ echo "tailing logs for ${tag} ..."; while read line; do echo -e "$zmx_${1} $tag $1${...
-2
votes
1answer
65 views

CD $Variable not working when used in a (Bash) Shell Script [duplicate]

File name: Test.sh #!/bin/bash ZDir="$(echo /usr/src)" cd "$ZDir" When I execute the script ./Test.sh, the command cd doesn't do anything.  If I try to do it directly in the bash terminal, it works ...
0
votes
1answer
44 views

Start new shell with positional parameters

With Python, I can start a session with positional parameters: $ python3 - aa >>> import sys >>> sys.argv[1] 'aa' However it does not seem to be possible with shell: $ sh - aa sh: ...
0
votes
6answers
312 views

On Linux terminals, why doesn't cd.. work?

On Windows/DOS terminals a cd.. works well. On Linux terminals the dots from the cd command have to be separated. I'd like to know how/why is this necessary for the parser to work. If no space is ...
-1
votes
2answers
142 views

How to copy files one by one to different folders?

In a directory I have files with the names: 01.txt 02.txt 03.txt In the same directory are folders with the names: 01.abc 02.def 03.ghi I need a command to copy the files to the folders one by one,...
1
vote
0answers
29 views

Associating pts and tty to a process

I am trying to find out which tty or pts is being run by which process. My research so far is that: tty is a kernel or backend terminal to handle lower level stuffs pts is a pesudo terminal to allow ...
1
vote
1answer
35 views

Using diff / patch to create a new file inside a directory

I'm learning about diff/patch and I don't understand why the patch file created by the command sequence below doesn't create the file create_me.txt inside the Org directory when I try to apply it. ...
0
votes
1answer
68 views

How to extract thousands of files where each file is in separate subfolder?

I have one folder containing three thousand subjects imaging data. Each subject's folder has many other folders in it. I want to use a loop to extract one file from each subfolder and move them into ...
0
votes
0answers
228 views

SSH: How to disable strict host key checking, but still be warned about new devices

I'm working for a company that involves sshing into several different devices with the same IP address and hostname, but unique private keys for ssh. What I'm trying to figure out is a way to disable ...
0
votes
1answer
58 views

crontab and scp file transfer via script

I have a script that exports logs from log management server and send those exports to the archiver server. When I run this script manually, it complete it's task without any problem. It download ...
1
vote
1answer
31 views

How do I make the system wait for an script inside of my script to finish its background processes

I am building the pipeline for a set of data and what I have for the main part is something like this #! /bin/bash time bwa mem -o bwa/mem/Stettler -M -t 96 -R "@RG\tID:Test\tSM:Stettler\tLB:...
0
votes
1answer
33 views

Redirecting all primary file descriptors using `exec` causes the shell to exit after program exists depending on which end closes the connection?

I've been practicing my Bash skills by creating reverse shells using various redirection operators. After having set up a nc listener: nc -lvp 4444 I run the following command: 0<&116-; ...
0
votes
0answers
17 views

settings put global http_proxy accepting syntactically incorrect proxies

I am working on an android device in kernel level, when I set an incorrect proxy through command adb shell settings put global http_proxy hhhh:8080 it is accepting without any errors. if i do ping ...
0
votes
1answer
37 views

Shell script cp command to a folder that will constantly change name

I have a script that downloads a folder. The folder has a fixed name with an ever changing number as a suffix, e.g. fixed_name_450. Each time I run to script the downloaded folder will have a new ...
1
vote
0answers
49 views

pidofproc or pidof working from init.d but not from /usr/sbin

I have a Linux service I'm supporting. It offers the usual start and stop commands. The designer created a wrapper command that is meant to control startup and retries of the main function. The ...
2
votes
0answers
32 views

How to chain multiple automatic responses to make for Linux build?

Currently I have a script capable of selecting the cpu subarchitecture for a Linux build, but selecting native leads to an infinite loop for selecting P6_NOPS Intel cpus. I there anyway to send the ...
0
votes
0answers
5 views

What is setting PULSE_PROP_OVERRIDE_application.icon_name? on Kubuntu 18.04

Sometimes (not always) the following environment variables with invalid identifiers get set in my shell: PULSE_PROP_OVERRIDE_application.icon_name=konsole PULSE_PROP_OVERRIDE_application.name=Konsole ...
0
votes
2answers
34 views

How to rename files in order

I need to sort and rename files in a test directory such that based on the bolded number the file will be renamed 1-5 in groups of 5. I was able to sort them but now need to rename them 1,2,3,4, or 5. ...
0
votes
1answer
34 views

I set my display resolution to 800x480 using xrandr but it changes to 800x800

I'm trying to change display resolution using following these steps: https://gist.github.com/debloper/2793261. I'm using 7 inch HDMI USB powered display and this is commands that I used: # # gtf 800 ...
9
votes
4answers
2k views

Performance of loop vs expansion

Need expert suggestions on below comparison: Code Segment using loop: for file in `cat large_file_list` do gzip -d $file done Code segment using simple expansion: gzip -d `cat ...
-1
votes
1answer
207 views

updates.sh - Command Not Found - Arch linux

I installed Archlabs 1 month later, today I noticed bin folder in ~ directory and Deleted it. After Reboot This errors Came out in polybar /bin/sh: updates.sh: command not foun And /bin/sh: ...
0
votes
0answers
79 views

How to connect to remote MongoDB with Authentication and SSH Tunneling

I am trying to connect to Remote MongoDB using the below credentials from ROBO3T and it is getting connected successfully. I am trying to replicate the same through .sh file i.e, shell script and it ...
0
votes
2answers
22 views

How can I know what is the binary value I receive in a tcp socket?

in a socket created in the following way: nc -k -l 3111 I receive this message: �...
2
votes
2answers
70 views

Looping through two sets of files in bash shell

I have 25 related pairs of files in a folder called Data. These files are named tcr1_r1.txt and tcr1_r2.txt, tcr2_r1.txt and tcr2_r2.txt, and so on until I reach tcr25… (or how many files pairs I have)...
5
votes
2answers
72 views

How to handle async subshell exit

Say I have this: set -e; ( docker stop notifier-server docker rm -f notifier-server exit 1 # explicitly exit with non-zero ) & wait; echo 'we are here now' will we always get to ...
1
vote
1answer
39 views

How to pipe app1 to app2, but show both output in terminal? [duplicate]

I would like to know how can I redirect the stdout of an app to an input of an another app but still see the app1 output. The source app is written in c, the second app is in perl. The purpose of ...
0
votes
3answers
114 views

How to read input lines with newline characters from command line?

I found this to get user input from the command line. But it is failing into recognizing the new line characters I put into the input. Doing: #!/bin/bash read -e -p "Multiline input=" variable; ...
0
votes
1answer
32 views

How to close/kill SSH connection when bash shell exits?

We are writing an application. As a part of it, we have to provide SSH access to each clients. In this process, we are providing SSH access to the client using a web UI. This ssh session is invoked ...