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
2
votes
1answer
269 views

How to save command result in variable in Jenkins shell build step

I want to run this script inside my Jenkins job. My goal is to save the cat output into a variable so that I can use it somewhere else. #!/bin/bash ssh myserver.com <<EOF echo "Start." CYCLE=$...
1
vote
0answers
21 views

Installing nvm using Makefile

I've set up a Makefile like the following: NVM := $(shell command -v nvm 2> /dev/null) setup: ifndef NVM @echo "Installing NVM" curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0....
1
vote
1answer
33 views

How to stop marking while in tmux copy-mode?

I want to mark and copy text, and then stay in copy-mode with the marker off, permitting me to move up/down without marking new text (see below). But after marking text and pressing space or y to ...
0
votes
4answers
70 views

How to pipe fd 3 to consumer instead of fd1 / fd2

I was hoping to do something like this: echo 'foo' >&3 3| cat Basically, I want to write 'foo' to 3, and then only pipe the data in 3 to cat. But the above doesn't work, I get: bash: 3: ...
1
vote
0answers
32 views

Is it possible to verify, whether a program has called `cfmakeraw()` to set its controlling terminal to raw mode?

Is it possible to verify, whether a program has called cfmakeraw() to set its controlling terminal to raw mode? I initially thought that it was possible to verify whether the terminal operated in raw ...
0
votes
2answers
70 views

Bash Time Difference

I have a log file and I need to make some calculations between two jobs to find time difference. In my log file I am supposed to calculate time between the jobs incoming request and candidate list ...
1
vote
1answer
73 views

Why don't `stty -a` list `raw` in its output, when any modern shell, like Bash, is said to operate in raw mode?

Why don't stty -a list raw in its output, when any modern shell, like Bash, is said to operate in raw mode? I understand that any modern shell should operate in raw mode, i.e: Input made available ...
-9
votes
1answer
108 views

Using bash, how to read specific lines of a file? [duplicate]

I am looking to read portions of a file, for example lines 30-80, then later lines 81-130, then later lines 131-161, etc. Is there a way to read specific sections of lines or bytes of a file using ...
2
votes
1answer
40 views

Symlink to a bash script unable to “see” an alias

I'm having some difficulty understanding a subtlety of how a bash script works with arguments when it's accessed via a symbolic link. The issue is most easily explained with commands and their output: ...
2
votes
1answer
62 views

How to add colour to /etc/sudoers.lecture

Having set a lecture with Default lecture=always and Default lecture_file=/etc/sudoers.lecture, I would like to add colour to it. ANSI escape characters show without escaping, and creating a wrapper ...
0
votes
2answers
52 views

Difference between chmod +x vs sudoing an executable

A user can execute an executable by : sudoing which allows a user to run an executable as the owner or by setting the execute bit, chmod u+x (or should it be chmod a+x ?). So what is the real ...
1
vote
2answers
46 views

Convert string in #!/bin/sh

Hi I have output like this [4251][7c3c] I need to get 517C3C I've tried decodeSerial() { serial=$1 #serial=$serial | sed -r 's/(\[|\])//g' #serial=$serial | sed 's/]//' #serial=$...
-1
votes
1answer
36 views

How to view/debug the interaction between the terminal and the shell?

I understand that the terminal intercepts control-codes as listed by stty -a, and that the shell (Bash) utilizes the Readline library to process its input, which it receives buffered after each key-...
0
votes
2answers
54 views

Why does this bash script terminate the calling process when it ends?

When this bash script is run backgrounded, it terminates the calling shell. Why is this? #!/bin/bash # # weird job control, background termination of parent shell problem set -eum echo "Do not go ...
0
votes
1answer
25 views

Octet binary format in shell script

i cut the ip add ect: 10.0.0.0/4 into octet then when i change the octet to binary, it only appear like 1010 not 00001010, how can i make the output with octet format like 00001010. I already try #!/...
22
votes
1answer
1k views

Is for(( … )){ … ;} a valid shell syntax? In which shells?

The expresion: $ ksh -c 'for ((i=0;i<10;i++)){ echo $i;}' 0 1 2 3 4 works correctly. I fail to find the description of this syntax in which the {...;} is replacing the ; do ...; done in the ...
1
vote
1answer
37 views

How to expand array elements containing variable?

I have an array in which every element may contain another variable. The array assignment is from a file as follows: FILE_CLEANUP_DIR_ARR=($(cat cleanup.list | sed '/^[[:blank:]]*$/d' | sed '/^[#]/d')...
-1
votes
1answer
54 views

Grep quotation mark inside quotation mark

example.txt alias znm="base64" alias asu="sed 's/.\{4\}/&™/g'" alias mmk="sed 's/\(.\{4\}\)\™/\1/g'" alias mmk="sed 's/\(.\{8\}\)\™/\1/g'" Desired output: alias asu="sed 's/.\{4\}/&™/g'" ...
4
votes
1answer
35 views

From where does “ps” on Android get user names?

I have an Android tablet that I got a terminal program from Google Play Store. When I issue the "ps" command, it shows various names for the users running the processes. There is no /etc/passwd file ...
3
votes
1answer
52 views

Disabling home folder symbol (~) in command line prompt

How can I set Bash so that in the command line prompt the home folder is spelled out (e.g. /Users/John) instead of displayed with the ~ symbol?
0
votes
0answers
30 views

Filter by default

I'd like to configure my interactive shell (e.g. bash), so that by default all command output will be piped to some filter, e.g. less. i.e., if I type # make it will automatically be interpreted as ...
2
votes
2answers
63 views

Export command not found in su - user

Starting with root, I want execute a sql script with another $USER. But I have to set the right $ORACLE_HOME and $PATH for $USER. With this command I receive error export: command not found su - $...
-3
votes
1answer
32 views

Capture lines from several files [closed]

There are 5 text files in a folder. Need to capture from 3rd line to last line from all 5 text files and concatenate them in a single file using shell script. Need code for this.
1
vote
1answer
72 views

Is there a POSIX shell which completely removes the need for `cat` and `dd` by using in-place operators?

In Vidar Holen's blog entry Useless Use of dd, he argues that dd is effectively useless, primarily because everything is a file and files can be piped. We have also seen regularly on all the *nix ...
1
vote
0answers
51 views

Timeout shell commands without the timeout command when job control is not available

I would like to automate the process of doing some benchmarks on a remote device using a serial connection, the benchmarks could potentially fail without stopping, so I would like to add a timeout to ...
0
votes
1answer
31 views

How to specify output file name using piping?

I am using find to return the list of files from a directory and its subdirectories: find $directory -type f -name "*.epub" Then I want to use a command that requires the input and output filenames ...
0
votes
1answer
25 views

How to restore timezone from RHEL 5.x to RHEL 7.x?

We have scripts to reinstall RHEL 5.x to RHEL 7.x and install our application, but I need to update timezone according to old one. So how to restore timezone from RHEL 5.x to RHEL 7.x using /etc/...
1
vote
0answers
62 views

Portable shell code to print alternative text

Playing on a question for codegolf.se I am out of ideas. Is there some other approach (reasonably short, of course) that I haven't tried? Given i contains either heads or tails, correspondingly ...
1
vote
1answer
57 views

Opening interactive python shell after running python script in background

python3 -i test.py opens an interactive python shell after running test.py. However, if I try to run it in the background with python3 -i test.py & the job stops automatically with a ^C and shows ...
0
votes
0answers
15 views

How to run the shell script on remote server from a windows shell script or a bash script?

I have created a shell script to upload git files from windows to bitbucket. Now I have placed that shell script in Linux box because the source folder exists on Linux was from directly I want to ...
1
vote
1answer
49 views

How do I create a temporary file in memory?

I need to create some (small) temporary files in my zsh scripts, and I want them to live on RAM so as to avoid disk IO. What are the idiomatic ways of doing this? I want it to work on Linux and macOS, ...
1
vote
3answers
42 views

How do I find values on a file that corresponds to another file and print everything in the latter one?

I have the following kind of file (file_1): 4.96798703303702 "YPL223C" 3.5545141639441 "YPL281C" 4.50082973953956 "YML042W" 5.43613972089831 "YMR107W" 4.81971559885503 "YBR072W" 4.31478270112112 "...
0
votes
0answers
24 views

How can I redirect output from the end of a pipe to the input of the beginning of the pipe [duplicate]

I'm trying to learn the intricacies of piping and redirection, and there's one thing I can't seem to manage to do. I'd like to try to get a loop going such that AA stdout -> BB stdin BB stdout -> ...
2
votes
0answers
18 views

Shell: short version of `<application> & disown; exit` for replacing the terminal with a gui application

On a tiling window manager starting a gui application from the terminal emulator leaves the terminal open alongside the newly started window. A solution for this is $ <application> & ...
5
votes
4answers
283 views

Why does cat'ing a file via ssh result in control characters? [closed]

I have a device in /var/iot/data which I'm trying to get the data from remotely. On the machine itself: # cat /var/iot/data | xxd -ps -c 32 80de004a030270055678013ac591e5c6abac2185f4319c8088e3 That'...
-2
votes
1answer
44 views

Need to fetch only the required part [closed]

We have a string as below: **XX_EMAIL_FILES FCP_REQID=9614696 FCP_LOGIN="APPS/sup12" FCP_USERID=5667 FCP_USERNAME="SRI" FCP_PRINTER="noprint" FCP_SAVE_OUT=Y FCP_NUM_COPIES=1 "...
0
votes
0answers
44 views

iTerm2 screen buffer not getting clear

I'm using bash as my shell and iTerm2 build 3.3.1 as my terminal emulator on Mac OS X 10.14.6 Whenever I use a type a long command, iTerm window overwrites my current line with the new symbols even ...
0
votes
0answers
16 views

Copy file from my local system to server , bypassing B, ie. My local is A, I have a jump server B and my main server C [duplicate]

import os cmd1 = "scp -oProxyJump=abc@testing.com foo.docx abc@test2:" os.system(cmd1) I was using A$ scp -oProxyJump=B thefile C:destination From https://superuser.com/questions/276533/...
0
votes
0answers
38 views

Terminal - Application behaves differently when launched as terminal argument vs terminal command

I use key shortcuts to launch commonly used applications in i3. Some of these applications are text-based (vim, calcurse) and require me to pass them as arguments to a terminal emulator (st, termite). ...
0
votes
1answer
22 views

How to enable “extended_glob” in tcsh?

I am looking to enable 'extended_glob' in tcsh shell and I tried these commands: setopt extended_glob shopt extended_glob But , None of these worked. Can anyone let me know a way to enable this in ...
2
votes
1answer
176 views

try/finally with bash shell [duplicate]

I have these three lines: export bunion_uds_file="$bunion_socks/$(uuidgen).sock"; "$cmd" "$@" | bunion rm -f "$bunion_uds_file" I need to make sure the last line always executes..I could do ...
0
votes
1answer
26 views

Naming conflict with File extension and Shebang in Linux? [duplicate]

I have seen some Linux scripts having Shebang different from the file extension. Ex: somefile.sh has #!/bin/bash inside it somefile.ksh has #!/bin/sh inside it somefile.bash has #!/bin/sh inside it ...
1
vote
1answer
39 views

Why does shopt -s nullglob remove a string with question mark in an array element?

This little setting drove me crazy: shopt -s nullglob I use it in my bash 4.3 script as a global setting to avoid errors scanning empty directories. Now I found a strange problem which I do not ...
-1
votes
1answer
35 views

docker function does not call itself recursively when using sudo?

I am on an Ubuntu EC2 instance on AWS, and I have this in my ~/.bashrc file: docker(){ sudo docker "$@" } export -f docker; since I trust docker, I basically run all my docker commands with sudo ...
1
vote
1answer
69 views

Shell redirection: <<<'foo' vs <(echo 'foo') [duplicate]

I've seen both <<<'foo' and <(echo 'foo') suggested as alternatives to echoing to pipes (echo foo | cat). When I use both of these constructs with cat I get: $ cat <<<'foo' foo $...
0
votes
1answer
25 views

How to configure remote machine to use local timezone on login?

I work on a remote Linux machine which is located in a timezone which is off by 9h from my local time. I spend most of my time working from the shell, dealing with files versions and logs. Because the ...
2
votes
3answers
47 views

Loop over numbered files and append on every line of file the content of another file with the same number

I have a lot of numbered *.csv files with different numbers of lines and just as many *.txt files. I want to append on every line of file 1.csv the content of file 1.txt, on every line of file 2.csv ...
2
votes
1answer
79 views

Calculate time difference in milli seconds:

INPUT & OUTPUT ERROR: 14:00:11,320 14:00:11,453 **Correct Output** : Time difference is 133 milli seconds. 14:00:13,097 14:00:13,124 **Output in Error** : line 4: 124000000 - ...
4
votes
2answers
79 views

Get city location from IP addresses inside a file

What a i need is to find the city associated with each IP address, I've stored them inside a file. For example, the file's content is: 99.203.11.34 99.203.11.37 99.203.11.47 99.203.11.51 99.203.11....
2
votes
2answers
49 views

How to correctly identify the order of parameters?

This is my assignment. The task is to output n longest lines from the input file(s). If there is no argument for n, the the default of value n is 5. If there is no files in the parameter, the standard ...