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
13 views

linefeed in bash script - to email

I am doing printf to a logfile and having that logfile send through mailx, however, it seems that the linefeed "\n" are not recognised or captured in the mail. Snippet of script as below (notice the ...
8
votes
4answers
11k views

How do I change folder timestamps recursively to the newest file?

I was wondering if anyone knows how to change the timestamps of folders recursively based on the latest timestamp found of the files in that folder. So for example: ...
4
votes
1answer
345 views

How to trigger a 2nd command when a specific command is run in the shell?

I'll explain my question with example. I run $ python manage.py to perform some action. I want to run another command $ xyz , just when any user runs the previous command. Thus, from now on, ...
12
votes
5answers
32k views

Difference between ls -l and ll?

I'm relatively new to programming as a whole and some tutorials have been telling me to use ls -l to look at files in a directory and others have been saying ll. I know that ls is a short list, but ...
0
votes
3answers
79 views

How to group a bunch of rows based on information from the first row?

I have a data file looks like : 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 3 3 3 3 3 . . . 1 0 4 4 3 1 2 0 0 0 3 1 1 2 1 1 1 1 1 1 0 1 1 3 . . . 0 0 0 0 0 0 0 3 3 1 1 2 3 2 1 2 2 3 1 2 3 1 2 2 . . . ...
4
votes
3answers
61 views

Force POSIX mode

Brace Expansion, eg {a,b,c} is not defined by POSIX. I would like to run my shell in POSIX mode. With Debian this is simple enough: $ bash -c 'echo {a,b,c}' a b c $ sh -c 'echo {a,b,c}' {a,b,c} ...
0
votes
2answers
73 views

Spaces in assignments in shell scripts

What is the difference between a. var=23 b. var =23 c. var= 23 d. var = 23 There is difference in space around the assignment operator. I am new to unix.
3
votes
5answers
2k views

gunzip a folder with many files

I have a folder with 36,348 files gz files. I want to unzip all of them. Running: gunzip ./* results in -bash: /usr/bin/gunzip: Argument list too long Whats the easiest way to get around ...
0
votes
2answers
256 views

Double quotes in bash

I am trying to create a bash file which calls a program that expects a parameter to submitted between two double quotes. Take a look at my file content. #!/bin/bash echo ./yowsup/yowsup-cli demos ...
0
votes
2answers
46 views

How to delete a line with a given word using SED function

I have a file .txt with inside ID VALUE test value_1 testing value_2 first value_3 second value_4 I'm trying to write a shell script which will delete a line corresponding to a ...
0
votes
2answers
83 views

how to subtract first value from the last one within a column across a row in shell?

I have a data file looks like : 1 1 1 1 1 1 1 1 2 2 2 2 3 3 3 3 3 3 2 4 5 8 9 10 13 17 19 29 30 32 33 50 700 800 900 950 first I want to insert space among each 3 identical values keeping each ...
11
votes
2answers
411 views

Why does `watch` make `ls /tmp` list contents of $HOME?

I'm trying to watch number of files in my /tmp/ directory. For this I thought this command would work: watch sh -c 'ls /tmp/|wc -l' But it appears to work as if ls had no arguments. Namely, I'm in ...
7
votes
5answers
4k views

Where do I change my shell?

If I wanted to use zsh, for instance, rather than bash, where would I make this change for the current user?
4
votes
1answer
56 views

How to remove a positional parameter from $@

Basically, I want to "pluck out" the first occurrence of -inf from the parameter list. (The remaining parameters will be passed along to a different command.) The script I have has the following ...
1
vote
0answers
25 views

Can I mask a program on the OS from the command line? [duplicate]

So, I wanted to know if it was possible to mask a running program (not visible from task manager) from the command line. Also, can I see all programs, hidden or otherwise from the command line?
0
votes
0answers
78 views

How to redirect linux command outputs to specific row and column in csv?

I'm working on Unix Build post documentation process, I have a CSV file to be filled in and uploaded for every new build, to ensure the servers are build as per the original request. The CSV file ...
3
votes
1answer
68 views

performance regarding “find” arguments' orders

I'm curious whether there are some distinguishing performance differences with different filtering orders when using GNU find. For example, I hope to search all directories in current path whose ...
0
votes
2answers
47 views

Correct way to set PERMANENT environment variables from script

I want to do a very simple install process for my app framework. I've got everything working, but I want to set two environment variables. I want to update the PATH and also set a HOME variable. I ...
0
votes
2answers
43 views

Echo a string with a variable in it without expanding/evaluating it [closed]

I've searched everywhere. Tried echo and print. Tried single and double quotes. But I have parsed data and assigned it to a variable and would like to then evaluate it for if there is a variable ...
0
votes
0answers
10 views

Jinja to populate shell script

I have written a shell script that creates datadog dashboards (ref. datadog monitoring tool) for the a cluster. I want to call these scripts in salt-stack state and pillar files to make the whole ...
1
vote
2answers
30 views

Using getline with NR in awk

I have a bash script which calls a awk script to print each line from the file name_list.txt #!/bin/bash awk -f parse_list.awk name_list.txt In the awk script, I am using getline with NR to print ...
1
vote
1answer
156 views

How to change a pom.xml version with linux shell script

i have a pom.xml contain a line <version>x.y.z-tag</version> where tag could be: snapshot, alpha, beta or release. and x.y.z is a number version like: 1.0.0 or 1.2.1 .... i want to ...
1
vote
2answers
35 views

Replace part of filename by directory name

I have folders named ACB* and in it among many other files, a couple of files called scanAC_* I want to delete the part called scanAC and replace it with the directory name it is in. For example, ...
2
votes
2answers
49 views

How to append data to a variable using \n as separator?

The new line characters seem to be lost, even though they appear within quotes. foo= for i in 1 2 3; do foo="$foo$(printf '\n')$i" done echo "$foo" 123 Now in practice, I don't want to add a ...
7
votes
2answers
705 views

What is the value of ${#1}?

Please explain the usage of ${#1} below: getlable () { if (( ${#1} == 0 )); then test="-"; else test="${1}"; fi; }
0
votes
1answer
16 views

Execute Terminal Command in Linux Kernel Hook

How do I execute the following command from a loadable Linux kernel hook: echo 5 > /sys/kernel/debug/ieee80211/phy0/ath9k/AggregationLimit
0
votes
1answer
19 views

get command line agrument by variable in shell script

I want to get the arg of a command from a var that has the index in it of the arg that I want. Something like this # command in terminal, `foo -r -f value_wanted` index="3" var=$"$index" echo $var ...
5
votes
0answers
57 views

Why does OS X `install` errors on redirected input when the same version of `install` on linux works fine?

I would like to use install command in order to create a new executable file with pre-populated content (e.g. with single pwd command in it). So I've extended this example which creates a new empty ...
13
votes
7answers
3k views

determine shell in script during runtime

As per my knowledge, to determine the current shell we use echo $0 in the shell. Rather I want my script to check in which shell it is running. So, I tried to print $0 in the script and it returns the ...
5
votes
5answers
334 views

How to group lines in file by two?

I have a text file like this: a b c d e f g How can I group those lines to obtain an output like this: a-b b-c c-d d-e e-f f-g I have to do this in shell (sh, csh, bash). I have found this: ...
0
votes
0answers
41 views

Pg_dump does not work in Cron

I have the command below and run it succesfully: /usr/lib/postgresql/9.1/bin/pg_dump -U dspace --format=c --file=/dspacebkp/dspace_db_$(/bin/date +\%m\%d\%Y)_uncompressed dspace I can see my new ...
0
votes
2answers
763 views

put rows of numbers into a column with shell script

I have a file with many lines, like 1 jfkdajfd 1 2 3 5 2 fkldfjld 3 fdkfloaf 9 10 4 fldfldkf 5 fdskf;ak 12 1 4 I want to get all the numbers and put them in a column in a file, like 1 ...
0
votes
0answers
32 views

Git “unknown revision” error when within bash script

I'm writing a shell script that needs to perform certain operations based on the last commit's message of my local branches with a name starting with "task". Here's what my script looks like ...
3
votes
2answers
64 views

What does “if echo $line | grep -F = &>/dev/null” do?

I'm not sure what the following line does in a bash script: if echo $line | grep -F = &>/dev/null then ... I know &>/dev/null is short for >/dev/null 2>&1, I'm not sure, ...
81
votes
4answers
76k views

How do I use pushd and popd commands?

What are the practical uses of both pushd and popd when there is an advantage of using these two commands over cd and cd -? EDIT: I'm looking for some practical examples of uses for both of these ...
1
vote
2answers
69 views

BASH how to save output of rm with timestamp?

I nearly have this working, This is a script that will run in CRON to keep the latest 10 backups, and remove anything else, I want to log this to keep track to make sure all is in good order, I have ...
4
votes
2answers
209 views

ps - what is the difference between -o comm and -o command?

On CentOS 7.0.1406 I get differing output when running ps -A -o pid,command | grep [r]esque than when I run ps -A -o pid,comm | grep [r]esque The latter returns nothing; the former what I would ...
89
votes
18answers
92k views

How can I get distribution name and version number in a simple shell script?

I'm working on a simple bash script that should be able to run on Ubuntu and CentOS distributions (support for Debian and Fedora/RHEL would be a plus) and I need to know the name and version of the ...
0
votes
0answers
31 views

Is it possible to ssh and execute a remote command with a single quote in it? [duplicate]

ssh user@host "mv \"/some/path/fi\'le.txt\" /some/new/path" It doesn't matter what I do, or what combination of quotes I use on the file, it gives the following: bash: -c: line 0: unexpected EOF ...
1
vote
3answers
3k views

Why doesn't alias work in AIX (Korn shell, .profile)?

I have these files in my home directory: drwxr-xr-x 3 meuser staff 256 Oct 12 13:11 . drwxr-xr-x 102 bin bin 4096 Sep 30 12:28 .. -rw------- 1 meuser staff ...
3
votes
4answers
68 views

Sticky entries in shell history

Is there a way one could make some commands "sticky" in a shell history? I want to save some favourite commands that would be searchable with Ctrl+R, like the rest of the history, but they should ...
5
votes
2answers
41 views

How to store a path built with wildcards and containing with spaces into a variable

Here's the situation (I'm on a Mac, OS X El Capitan): # This works: $ cd /Applications/Adobe\ Illustrator*/Cool\ Extras.localized/en_US/Templates/; # These do not work: $ ...
6
votes
5answers
1k views

How do I break up a file like split to stdout for piping to a command?

I have a large .sql file full of SELECT statements that contain data I want to insert into my SQL Server database. I'm looking for how I could basically take the file's contents, 100 lines at a time, ...
8
votes
5answers
9k views

How to put a newline special character into a file using the echo command and redirection operator?

I would like to create a file by using the echo command and the redirection operator, the file should be made of a few lines. I tried to include a newline by "\n" inside the string: echo "first ...
2
votes
2answers
37 views

Find commands/function whose name matches a value

I am looking for some command e.g. match ls which should match commands like ls, alsa asls,.. and return them. I preferably want it to cover both all commands and defined functions. Is there a builtin ...
12
votes
3answers
2k views

Can git configuration be set across multiple repositories?

Git seems to support configuration values at three levels: Per-system global settings (stored in /etc/git-core) Per-user global settings (stored in ~/.gitconfig) Per-repository local settings ...
17
votes
4answers
12k views

Arrays in Unix Bourne Shell

I am trying to use arrays in Bourne shell (/bin/sh). I found that the way to initialize array elements is: arr=(1 2 3) But it is encountering an error: syntax error at line 8: `arr=' unexpected ...
2
votes
2answers
24 views

exclude target redirection file from being processed in for loop

This will cause LIST to grow very large (even a couple of GB in a short time etc): $ for i in *; do echo $i; cut -d ' ' -f1 $i ; done > LIST For example, after 10 seconds: $ wc -l LIST ...
4
votes
3answers
36k views

How to add arithmetic variables in a script

I want to accumulate the line size of a number of files contained in a folder. I have written the following script: let a=0 let num=0 for i in folder/* do num=`cat $i | wc -l` ...
2
votes
3answers
25 views

Extract lines from text with string as input

How can extract lines that match the regexp string ^li from the text (not a file) below using sed or something? linux loan litmus launch I tried grep but I couldn't find a way to search within ...