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)

3
votes
2answers
88 views

Iterate Through Sets of Command Arguments in Bash

I have multiple "sets" of arguments for one command that I need to run in sequence (well, in parallel, technically). I also need to repeat the same logic after running each command. #!/bin/bash ...
0
votes
1answer
89 views

How to save and use latin unicode in a shell script?

How can I use accented Latin characters like these (or any other unicode char really) in my echo statements comments? À à Á á Â â Ã ã É é Ê ê Í í Ó ó Õ õ Ú ú Ç ç Ñ ñ
0
votes
2answers
150 views

Get cpu usage average for the last 5 seconds

I am trying to find an alternative to this command: mpstat 5 1 Even though it works as i need, but it have a delay of 5 seconds, i need something similar, but that will give me instantly the CPU ...
26
votes
3answers
1k views

Official list of programs to be included in Linux?

Is there a standard that I can refer to for the list of programs (e.g. cat, ls) that must be included in Linux?
2
votes
2answers
121 views

Uncompressed .lzo files in parallel and then delete the original .lzo files

So I have .lzo files in /test01/primary folder which I need to uncompress and then delete all the .lzo files. Same thing I need to do in /test02/secondary folder as well. I will have around 150.lzo ...
14
votes
3answers
3k views

Why $SHELL doesn't change when I run new shell?

$ echo $SHELL /bin/bash $ /bin/ksh93 $ echo $SHELL /bin/bash $ file /bin/ksh93 /bin/ksh93: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for ...
-1
votes
2answers
84 views

execute multiple commands after ssh

I need to pass a bash command into another process that needs to do the following: ssh into a computer. This does not require a password prompt. set up some environment variables: source ...
8
votes
3answers
473 views

Command redirection to multiple files: command >file1 >file2 [duplicate]

I have this command: cat somefile >file1 >file2 After I executed this command I can't figure out why file1 has nothing in it. It should have the output of the first file (somefile), but ...
1
vote
0answers
7 views

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

I want to run a script that changes the hostname and have my bash prompt (PS1 variable) update immediately with the proper hostname. How do I make this happen? I run this #!/bin/bash # Usage: ...
3
votes
2answers
130 views

How to split a file by counting digit numbers within a row?

I have a file with 45000 character within each line and I I want to split the original file based on specific numbers of character within a line. as an small example my input file looks like: ...
0
votes
2answers
32 views

Passing timestamp variable from shell to gawk [duplicate]

I want to take time difference of two time stamp but getting an error while passing timestamp variable from shell toawk. Shell code: FTIMESTAMP="2015-07-01 12:30:50" gawk -v FTIMESTAMP=$FTIMESTAMP ...
1
vote
4answers
55 views

Symlinks according to directory depth

I have the following directory structure that I need to create, and while doing so, I need to also create the zip files which are symlinks. /a/2015-08-17/a.zip /a/2015-08-17/a_b/a_b.zip ...
3
votes
3answers
607 views

How to practice for command line? [closed]

I am reading The Linux Command Line: A Complete Introduction to learn about the command line. The book is great. However, there is a major problem for me: It does not have exercises/projects at the ...
0
votes
1answer
84 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
266 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
57 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
481 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
74 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
390 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
387 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
151 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
166 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
136 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
107 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
309 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
42 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
151 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
37 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
530 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
650 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
206 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
348 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 ...
31
votes
12answers
12k 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
364 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 ...
6
votes
2answers
59 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
735 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
96 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
395 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
344 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
52k 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 ...