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, …).

learn more… | top users | synonyms (1)

0
votes
1answer
73 views

Command line processing - tokens and metacharacters

I am just learning about command line processing, and hoping someone can confirm how I am interpreting the following statement. In the book I am reading the first step in command line processing is: ...
3
votes
1answer
249 views

Reading keypresses in shell using trap and Unix signals

I am having trouble understanding the purpose of trap and the multiple stty invocations in the snippet below. I was hoping someone could give me a rundown of what is happening. getkey() { local ...
2
votes
1answer
53 views

Shell Script - Redirected output to a file and results are not as expected in first run

I have redirected the output of the command which returns some times 2 rows, 5 rows.. 100 rows etc in the file.. and i will use this file in if condition later to check some other conditions.. ...
1
vote
2answers
433 views

How to find PID of a while loop?

I run this command in Bash terminal while [ 0 ]; do i=1; echo $i; done Before running this loop, in another tab of gnome-terminal I did $ps aux | wc -l 192 While the loop is still ...
3
votes
2answers
68 views

Remove all but the latest backup file monthwise

I've got a directory, containing lots of weekly generated files with names like db_20130101_foo.tgz db_20130108_foo.tgz db_20130115_foo.tgz ... and so on. Over the years, the disks will get ...
2
votes
2answers
344 views

linux equivalent to AIX proctree command to show all child and parent processes of a given PID

Sometimes I'm looking for an equivalent for the AIX proctree command which displays all children and all ancestors of a specified PID and can be sometimes quite useful for troubleshooting purposes. As ...
0
votes
2answers
379 views

How to match stream against white-list and black-list?

How can I duplicate a pipe stream (output from another program) so that for every line, I can check whether it matches independent regular expressions (ideally, reuse a grep command with options like ...
1
vote
0answers
31 views

Not able to find Output files for multiple input using for loop [duplicate]

I am trying to use a for loop to use multiple files for trimmomatic but the output files are kept in a different directory that has pre-installed directories with Input names. But when I am running ...
1
vote
3answers
144 views

Combination of find and grep command with exec option

I am trying to find all files inside /lib /lib64 folders that contain "lib" in their names and print that file names without extensions (.so or similar), avoiding identical names in output. My way ...
1
vote
2answers
164 views

Result of combination of Ctrl+c and then Ctrl+z in shell

Which signal will be sent to the running process after sending the Ctrlc after 500ms of Ctrlz? I have tried to give the Ctrlc after Ctrlz but I didn't get the exact answers for this.
-1
votes
2answers
52 views

how to run a command in many files by running the command only one time?

I would like to run following command on 31 separated file name chr1.txt ... chr31.txt , and get 31 outputs only by one run. this is command : cat input.txt | sed 's/.\{5\}/& /g' > ...
0
votes
1answer
71 views

Script inside bash shell thats inside another bash shell [closed]

I'm trying to run a simple program #!/bin/bash bash echo "Hello World" But the program only gets as far as the 'bash' command on line 2. Why can't the program run line 3? The program terminates at ...
2
votes
1answer
133 views

Run commands in a terminal, then let me type more commands

I wrote this script to create multiple tabs in the same terminal window and run commands in them: #!/bin/bash #Use the commands as: #--tab-with-profile=Default --title=<SPECIFY THE TAB TITLE ...
0
votes
1answer
98 views

#! /bin/bash or #! /usr/bin/env bash? [duplicate]

I'm trying to write some provisioning shell scripts for Vagrant dev environment. I'm used to start bash scripts as follows #! /bin/bash But after surfing through some git repos I found out that in ...
0
votes
4answers
300 views

How to sum up values of each two rows across their line in linux

I have a data like this: input.txt 1 0000100101000000 1 0000010100000000 2 1110000001000000 2 1111000000001000 3 0000000111111111 3 1111111100000000 4 8888345500000000 4 0000000000000000 and I ...
-2
votes
1answer
41 views

How can I write a bash script that tells me how many hours there are from 23:43 to 02:10?

How can I calculate with hours and minutes in bash? For example say I want to write a script that takes two timestamps and tells me how many hours there are in between them, how can I do that? $ ...
1
vote
3answers
1k views
0
votes
1answer
127 views

Login to multiple servers and run a command having passphrase

Already passphrase has been setup and now I want to login to multiple servers and run a command against all of the servers. I tried this #! /bin/bash for HOST in $(cat servers.txt ) ; do ssh -o ...
0
votes
0answers
35 views

Writing shell plugins

How do you write native plugins for major shells? With Bash -- it's pretty clear (although, IMO, it could have been a lot prettier) -- just get the source and hack on examples/loadables. But what ...
4
votes
5answers
472 views

Bash - PS1 not Updating With Proper Hostname after Hostname Change in Script

This is a copy of my post from stackoverflow; I realize I should have asked it here... I want to run a script that changes the hostname and have my bash prompt (PS1 variable) update immediately with ...
4
votes
5answers
607 views

How to split a file based on information within a column in linux

I would like to separate those rows where the value in second column is smaller than a specific value. example input: id1 19501112 id2 19831207 id3 20001212 id6 20000101 id10 20061213 id11 20081212 ...
-1
votes
0answers
16 views

How to accumulate values of each two rows across a line in linux? [duplicate]

I have a data like this: 1 0000100101000000 1 0000010100000000 2 1110000001000000 2 1111000000001000 3 0000000111111111 3 1111111100000000 and I want to sum up the values within eachtwo rows with ...
4
votes
2answers
201 views

Why do `env var=value` allow arbitrary name in var?

Reading env POSIX documentation: Some have suggested that env is redundant since the same effect is achieved by: name=value ... utility [ argument ... ] The example is equivalent to ...
1
vote
1answer
250 views

Can't open terminal because of settings

Hello. I have a problem with my terminal: I can't open it. I have done a thing like written here I have checked 'Run a custom command instead of my shell' and typed in 'echo Hello World'. Now I can't ...
30
votes
12answers
11k views

Object-oriented shell for *nix

Preface: I love bash and have no intention of starting any sort of argument or holy-war, and hopefully this is not an extremely naive question. This question is somewhat related to this post on ...
3
votes
1answer
80 views

Export a selection of environment variables with correct escaping

I want to export some environment variables which I set in a dash script to a file: myvariable="line 1 LINE=3 some characters: # \" \$ line 5" myvariable2="abc" export myvariable myvariable2 ...
5
votes
3answers
347 views

Use shell's “*” glob, but exclude one file and don't match directories?

I've got a makefile rule that builds a zip/tarbar for distribution. In the recipe, it does some "value added" things, like ensure CR/LF's are correct, and ensures execute bits are correct before ...
5
votes
2answers
55 views

How can I make readline add pre-“typed” text on terminal startup?

By pre-"typed", I mean the interactive console has code text waiting for the user to (edit and) run by simply pressing enter. It looks like something readline should support, but a confirmation that ...
1
vote
1answer
725 views

Why does redirection in crontab result in a zero byte file?

System: Xubuntu 13.10 When I have this crontab entry */5 * * * * cat /home/dbk/.bash_aliases &> /home/dbk/Desktop/junk junk has a byte size of 0. Running $ cat /home/dbk/.bash_aliases ...
0
votes
1answer
88 views

CentOS and Stop Shell Script running on screen

I'm trying to automatize my system, sorry but I'm not very experienced on Linux distros, actually using CentOS 7. Every time I restart the machine I need to do: screen -S bun then on that screen I ...
3
votes
2answers
354 views

Passing script string to ssh from within a bash script function - variable evaluation problem

I'm trying to write a bash script that runs a remote script via ssh as below: #!/bin/bash logfilepattern="*drupal*.gz php*.gz error*.gz" function getlogcounts { echo "in getlogcounts" echo ...
6
votes
3answers
4k views

How to prevent command injection through command options?

I have an wrapper application where I need to let the user specify custom options to pass to a simulator. However, I want to make sure the user doesn't inject other commands through the user options. ...
19
votes
5answers
1k views

Commands to learn about an unfamiliar system [closed]

You log in to an unfamiliar UNIX or Linux system (as root). Which commands do you run to orient yourself and figure out what kind of system you are on? How do you figure out what type of hardware is ...
19
votes
8answers
1k views

How do I source another process's environment variables?

If I examine /proc/1/environ I can see a null-byte-delimited string of process 1's environment variables. I'd like to bring these variables into my current environment. Is there an easy way to do ...
1
vote
2answers
27 views

How do I prevent $@ from clashing with double quote in bash?

The following example returns "a b" instead of expected "a b c": test() { bash -c "testargs() { echo \$@; }; testargs $@"; } test "a b" c It seems it's a quoting issue. How do I solve it without ...
5
votes
2answers
334 views

Is it possible to exec some commands in a subshell without immediately exiting afterwards?

I use the fish shell and would like to be able to "source" some shell scripts written with sh-compatible syntax, which fish cannot read. For example lots of software expects you to source some shell ...
20
votes
3answers
50k views

how to output text to both screen and file inside a shell script?

Currently I have a shell script which logs messages to a log file like this: log_file="/some/dir/log_file.log" echo "some text" >> $log_file do_some_command echo "more text" >> $log_file ...
0
votes
0answers
84 views

Check OpenSSL version in Android with java runtime or shell command

I have a problem with checking OpenSSL version in Android device. I've tried to: grep OpenSSL from system/lib/libssl.so with java runtime.exec. but it doesn't work? Anyone can help me, how to make a ...
0
votes
1answer
79 views

Bash shell functions and understanding shell shock

I asked a related question on defining and using shell functions in bash. In this question I want to ask specifically which way of defining function can lead to shellshock. I did some tests and I want ...
1
vote
1answer
62 views

bash error on eval containing blank space

I need to triggeer a bash passing parameter with a format [ variable_name="value" ] like this: ./test.sh ip='164.130.21.98' hostname='whatever' pwd='/test' ftpcmd='CWD debug' user='stefano' On ...
1
vote
2answers
52 views

source file as an argument?

I've read up on using source to run another file inside another: source ./filename but I want to do this inside a command as an argument.. (or set of) Here is how the command goes: command \ ...
-4
votes
2answers
46 views

A script that can check subdiractories for a file that contains 'hello' and gives back directory name

i need a script where you give a directory name as a parameter and the script check all the subdirectories .php files and if any file contains a string 'Hello' then the script list the matches files ...
1
vote
2answers
121 views

Awk condition along with header

I have a dummy employee.txt file as follows to play around with awk: 100 Thomas Manager Sales $5,000 200 Jason Developer Technology $5,500 300 Sanjay Sysadmin Technology $7,000 ...
0
votes
3answers
79 views

How do I create files using the lines in a .txt file?

For example I have a file called fileNames.txt. cat >fileNames returns abet able abacus How do I use fileNames to create abet, able, and abacus as .txt files? I tried using pipes with cat ...
2
votes
1answer
53 views

String a command after a command that ends in & - EX: nohup > log & && rm log

So I guess there is actually two parts to this question, because I don't want the RM to go untill the nohup command has finished, but the problem is, I love to string together commands, but my nohup ...
6
votes
3answers
637 views

Clear or disable aliases in zsh

I installed oh-my-zsh to make terminal use a bit easier. One thing that bugs me though is the prolific aliases added by it, like "ga", "gap", "gcmsg", "_", which are harder to remember than the ...
0
votes
1answer
43 views

expansion with escape character help

I am having trouble doing expansion with this because of the escape character. UNF\1122 Right now I am trying to stick with the really simple example of: ps -ef | grep $USER Eventually after I ...
1
vote
1answer
194 views

Is it possible to establish a Socket session (between Server and Client) using shell commands ?

From what I read (only the very outline, i do not know C Language) a Socket session is established between a server and a client by calling functions for both of them in a certain order. It starts ...
0
votes
1answer
42 views

how to extract some rows in a data file by comparing with another data file? (merging) [duplicate]

I have 2 different file : first file: id1 19501112 id2 19831207 1d4 20001212 id6 20000101 id10 20061213 id11 20081212 id12 20100109 id13 20101218 id14 20101212 id15 20111111 id16 20150919 id20 ...
3
votes
1answer
131 views

Sending sigaction / sigqueue through shell

I have a c++ program that handles several signals to perform different actions, using signal: signal(SIGHUP, signal_handler); I wanted to extend this signal handling to allow me to send ...