Stack Exchange Network

Stack Exchange network consists of 175 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 [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.

1
vote
2answers
42 views

Why is SHELL pointed to /bin/sh in a Csh script?

Yes, I know C-shell is bad. No, I did not choose C-shell. Yes, I would prefer to use a proper shell. No, I cannot switch to a better shell. I have a very simplistic script: /tmp/env_test.csh #!/...
-4
votes
0answers
23 views

write the command to find the wild character in unix [on hold]

I have one file with 10 columns . Need to check which column in having wild character in file through unix command like qw|23|er5|ght|%ft.f%\|Tar need to know which column in having extra ...
0
votes
1answer
36 views

How to know from which bash version a built-in is made available?

Is it possible to know from which specific version of bash a particular built-in is made available from the command-line? Is it only possible by browsing through release notes for each of the versions ...
0
votes
1answer
42 views

Make alias for shell scripts

I'm working my way through the Wicked Cool Shell Scripts book. I've created a script, following the book's code, which can be found here. I'm trying to make an alias for this script so I can just call ...
0
votes
1answer
36 views

Create a separate file containing rows sharing one specific column with same value!

For instance, I have a data like below: Transmit.123 Invite Members A Transmit.123 Invite Members GC Transmit.111 Invite Members F Transmit.222 Invite Members DE Transmit.222 Invite Members H ...
-1
votes
1answer
22 views

GCC .lib file format not recognized by shell script

I am trying to run a shell script for gcc arm, but while running the script I get this error File format not recognized The end of the script, line 70 is the last one: include $(...
1
vote
2answers
34 views

Each element in a list repeated a different number of times

I have two lists chr=(1 2 3) # either chr=(1 2 3) or chr=({1..3}) is fine pos=(2 3 5) and I wanna have the output 1 1 2 2 2 3 3 3 3 3 1st element of one list is repeated as many times ...
0
votes
3answers
65 views

I have if else question but I am not sure the answer is true? [duplicate]

I am running this on Linux: $ number=4 $ test $number -eq 4 $ echo $? 0 $ test $number -lt 2 $ echo $? 1 Are the results (0 and 1) true ?
0
votes
2answers
31 views

Convenient way to cd into a frequently-used dir? [duplicate]

A dir I cd into a lot has a really long path. I'd like to reduce keystrokes. I have tried this... sudo ln -s /mnt/c/Users/me/ho/hum/bin /mybin It works, but something about it seems wrong. Is ...
0
votes
1answer
23 views

Usage of variable in {..} [duplicate]

Can someone explain why the following code for i in {1..5};do echo "hello" done prints hello hello hello hello hello but the following num=5 for i in {1..$num};do echo "hello" done prints ...
1
vote
4answers
70 views

Is there an alphabetic equivalent of nl or seq?

I have a file where I'd like to number the lines using "the alphabet" (simple ascii a, b, c, etc.) instead of numbers. So where I could do: nl somefile I'd like to do something like: abc somefile ...
0
votes
1answer
36 views

execute command as root and then switch back to user in shell script

I have a shell script that is started by a specific user, this user is not and cannot be in /etc/sudoers. Inside the script there is just 1 cp command that needs to run as root, then I need to switch ...
2
votes
2answers
39 views

How to squelch sh errors from imported bash functions?

So I've got a .bash_aliases file with many exported bash functions inside; a good deal of which are incompatible with sh... The problem is that sh is used all over my laptop (OS X) and linux machines ...
6
votes
3answers
189 views

Redirecting output only on a successful command call

I want to redirect the output of a command (diff in this case) to a file but only if there is a difference in files I'm comparing. For example, imagine I have three files a, b, and c where a and b are ...
0
votes
1answer
35 views

Getting Error with system() in perl

' Number found where operator expected at ./scripttemp.perl line 5, near ""sed -i -r "4" (Missing operator before 4?) String found where operator expected at ./scripttemp.perl line 5, near "}" ...
0
votes
2answers
38 views

Cannot escape '?' character in variables (unix)

I have been looking for this question everywhere, but I didn't find it and there doesn't seem to be any kind of answer yet to my current problem, which, frankly, doesn't even make sense. So, what I ...
-1
votes
2answers
48 views

Display contents of the file searched by grep or find command [closed]

I have lots of directories in a certain directory and I am trying to find a specific file present in there. I used grep command recursively and was able to locate the file being present in there, but ...
1
vote
0answers
72 views

Shell script cannot find file [duplicate]

I am trying to install a gcc-arm version but run into trouble while trying to run the setup shell script. Following step 2 in the prerequisites I downloaded GNU ARM embedded toolchain v4.9-2015q3. ...
1
vote
0answers
26 views

Git add, commit, push from bash script

I'm trying to write a simple cron job that will keep my org-mode files in sync with a GitHub repo by committing every now and then. For some reason, it always manages to commit the files, but even ...
24
votes
3answers
4k views

How can I detect if I'm in a subshell?

I'm trying to write a function to replace the functionality of the exit builtin to prevent myself from exiting the terminal. I have attempted to use the SHLVL environment variable but it doesn't seem ...
0
votes
1answer
46 views

How can I upgrade a primitive Netcat shell to a fully-featured login shell with tab-completion and line editing?

How can I upgrade a primitive Netcat shell to a fully-featured login shell with tab-completion and line editing? Suppose I start a remote (reverse) shell using Netcat as follows: nc -lvp $port nc $...
0
votes
1answer
35 views

Translate a single line into a file with one shell command

I'm looking for a convenient command to run from my terminal. At now I'm using $> FILE=./file_for_translate.md && ROW=84 && \ DATA=$(sed -n ''"$ROW"'p' $FILE | trans -no-init -no-...
1
vote
2answers
37 views

Flush the pipe/printf buffers externally for already running process with known PID

I am writing a data logging app, all programs are started like: ./program > out.bin The data collector periodically pools the stdout output files and reads the data. The issue is that the IO ...
-4
votes
4answers
87 views

Linux Shell: Extract values separated by pipes from a file

I have the following values in a file: line 1: 31915 line 2: Salchipapa|papa|salchicha|aceite|queso I need to get the values papa, salchicha, aceite, queso that means that i have to get the values ...
1
vote
1answer
50 views

$PATH: output showing malicious program?

I read that using echo $PATH, for NON-root users should resemble: /usr/local/bin:/bin:/usr/bin:/usr/X11R6/bin:/home/username/bin: I read that using echo $PATH, for ROOT users should resemble: /...
1
vote
3answers
238 views

Why does a file move/copy function only move one file at a time when using the “*” wildcard?

function mv1 { mv -n "$1" "targetdir" -v |wc -l ;} mv1 *.png It does only move the first .png file it finds, not all of them. How can I make the command apply to all files that match the wildcards?
0
votes
1answer
54 views

Recursive shell call

I have a use case where Dummy.sh load data and fix.sh fix problematic data and load data again. Here I have to implement retry logic, if fix script is not able solve problem in 3 attempt. But its ...
-3
votes
0answers
22 views

Curl problem in Python [migrated]

I'm using python 2.7 and I need a python script like following. The problem is waiting file download everytime for result if curl time condition is True. I want to get result without waiting file ...
6
votes
4answers
482 views

Write a function that checks if a string starts with or contains something

I want to write a function that checks if a given variable, say, var, starts with any of the words in a given list of strings. This list won't change. To instantiate, let's pretend that I want to ...
1
vote
1answer
21 views

Bash | Txt file > tmp> process tmp> ouput

recently we got Jump Host to interact with all our devices. It's red had 6.x and we have no root access. We can script on Autoexpect and bash only - no modules possible. Source: I have 5000 devices (...
-1
votes
0answers
28 views

How to add add additional columns to an sql insert query using shell script?

Example: $ cat data.txt insert into "APS"."HEARTBEAT"("adress,"date") values ('LIVE LIVE-22.',TO_DATE('03/15/2019 23:00:05', 'MM/DD/YYYY HH24:MI:SS')); Desired output: insert into "APS"."HEARTBEAT"(...
1
vote
0answers
33 views

Find where exactly a script is being called from

There is a script in a server (known location) that copies a file from one location to another, eg : cp /dirA/file.DAT /dirB/file.DAT This script is being run daily and copies the file, but I don't ...
4
votes
3answers
1k views

Why does ''cat "${1:-/dev/stdin} | … &>/dev/null'' work in bash but not dash?

Script: #!/bin/sh # # reads stdin/file and copies it to clipboard # clears it after 30s # cat "${1:-/dev/stdin}" | timeout 30 xclip -i -selection clipboard -r -verbose &>/dev/null & I ...
0
votes
1answer
42 views

Make multiple directories from Mediainfo information to put music in

I have a bash script that goes through my music folder, gets all the song metadata with mediainfo and is intended to make folders out of all the artists' names, but it fails. This is the code so far: ...
0
votes
2answers
26 views

Echo shell log while entering and then exit

While I type a command, this command will authenticate with a remote server and do a bunch of things. If pass, it will give me a bash shell with its environment. My goal is to save these log which ...
-1
votes
1answer
28 views

simple systemd service for execution of shell script

Im trying to start a simple .sh file and it says Failed at step EXEC spawning /etc/start.sh: No such file or directory Content of the gnome.service [Unit] Description=Description for sample script ...
0
votes
2answers
46 views

How to write routine to escape double quotes in a JSON string [closed]

I have to be efficient so I can't use tools like jq which loads up a big binary executable. I just want to escape double quotes in a string so it's safe for JSON. This isn't good enough: echo ' bad \"...
1
vote
0answers
42 views

How to replace Bash with Xonsh [duplicate]

I am using Linux Mint 19.1 I want to use Xonsh as my default shell. According to their documentation, The latest version of Xonsh can only be installed using conda, pip, or from source. conda: $ ...
2
votes
1answer
80 views

Shell script returning “Running: command not found”. Not sure why

When I am setting a variable to a command, I am getting the answer along with the error "command not found". Below is the command in the script. #!/bin/bash fs=$(ps -C "daemon_name" > /dev/null &...
0
votes
0answers
8 views

NOEXEC flag prevents users to do /bin/su

I need to prevent the shell escapes in our systems.These are the sudoers file entries. Cmnd_Alias OD_DBA_2 = \ /bin/rm /*/apps/*, \ /bin/rm -[a-z]*...
1
vote
2answers
22 views

How can i check if my host command in script got a valid ip

Suppose we only have 1 parameter host $1 How can I check if the above command will give me an answer or: Host $1 not found (NXDOMAIN) and instead of showing an error not found, I would like to ...
1
vote
1answer
23 views

How to count how many times each line appears in a file

I have something like this teithe.gr List item deitel.com parinux.org cs.vt.labs.edu cs.may.ie csse.monash.edu.au amazon.com amazon.com teithe.gr teithe.gr I just want to know how can I count each ...
2
votes
1answer
63 views

Redirections and Return Codes

So I have a program that may or may not segfault (./segf) that also writes other data to stderr. When the program segfaults, its return code is 139 (i.e. echo $? will print 139). I would like to ...
0
votes
2answers
29 views

Using grep and logical operators for pattern matching within shell script

Im trying to develop a script that finds a specific pattern in the output of the dig command running against a list of domains. To do this I'm using grep but having difficulty implementing this using ...
0
votes
2answers
75 views

Check if named pipe is open for reading

Right now, I have this crappy check to see if a named pipe is being read from: is_named_pipe_being_read() { local named_pipe="$1" echo "unlocked" > "$named_pipe" & pid="$!" #...
4
votes
2answers
92 views

SHELL environment variable still points to zsh after using bash

I am trying to jump between zsh and bash. By default, I have zsh as my shell, I can know this by typing: echo $SHELL and I get /bin/zsh However, I want to open Bash, so I type /bin/bash; I assume I ...
0
votes
1answer
27 views

Bash - How do I pass in parameters using an array?

I am trying to run a program with many parameters as follows: ./some-program -c 1 -c 2 -c 3 ... How should I create such a command in Bash shell scripting?
2
votes
1answer
30 views

How to write something to named pipe even if there are no readers

I have this little test script: rm fooo | cat mkfifo fooo echo 'bar' > fooo # blocks here echo 'done' I am guessing that because there is nobody reading from the named pipe, that the write call ...
0
votes
0answers
14 views

Question about su and environment variable [duplicate]

From this question: How can I preserve an environment variable across su -? and from man I know that su - <other users> will: clears all environment variables except for TERM initializes the ...
-1
votes
2answers
34 views

Why doesn't back-slash yield non-zero exit code

If run: true \ false; echo $? I get an exit code of 0. Does anyone know why that is?