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)

19
votes
2answers
761 views

Tilde (~) inside working unix directory

So, Im working in a UNIX environment and I noticed that inside my working directory, which is miles miles away from my UNIX home, there is a ~. Now, once in the past, I did rm -rf ~ from my working ...
1
vote
3answers
41 views

List files in a directory with a certain extension

I created a file called ~/usrlibs.txt, which contains the number of files that begin with lib and end .a found in the /usr/lib directory. I tried: ls -l /usr/lib/lib .a | wc -w > ~/usrlibs.txt ...
2
votes
3answers
37 views

Reuse similar flags for multiple commands

Let's say I want to execute several commands with similar flags such as: du -sh / --exclude=/dir1 --exclude=/dir2 --exclude=/dir3/dir4 tar cvf archive / --exclude=dir1 --exclude=dir2 ...
3
votes
1answer
63 views

Run wc and display only the word count

I have been trying to create a file called ~/dictwords.txt, which contains the number of words found in the file /usr/share/dict/words. I already created the file then I removed it because I did it ...
5
votes
4answers
140 views

Help with “/usr/bin/stat: Argument list too long” error

I need to get the list of files(.log/.lst) present in a directory($logfolder) whose creation date is in a specific $year and $month stat --format='%y %n' $logfolder/* | grep "$year-$month-"| ...
8
votes
2answers
342 views

disable CTRL-D window close in terminator (terminal emulator)

I am often logged in through multiple SSH sessions. To logout from my sessions, I press CTRL+d, until I am back on my local machine. However, sometimes I press once too many, and my terminal exits. ...
4
votes
1answer
77 views

Launch background processes in one group and later kill them all

The other day I tried writing a script that would kill a PID and all its children processes, but after spending some time on it, I decided it wasn't trustworthy, because sometimes some of the children ...
7
votes
6answers
720 views

How to read first and last line from cat output?

I have text file. Task - get first and last line from file after $ cat file | grep -E "1|2|3|4" | commandtoprint $ cat file 1 2 3 4 5 Need this without cat output (only 1 and 5). ~$ cat file | ...
0
votes
2answers
32 views

list files and store it in variables

im new with shell programming. my goal is to give the user a selection which file should be run. i catch all available scripts in one var with: var=$(find script*) so far so good.. this is the ...
1
vote
2answers
37 views

How to get text at start up of terminal

How to get text at start up of terminal as shown in this image.It should show whenever i open terminal.
6
votes
1answer
51 views

How do I use colors in the MOTD?

I edited the default /etc/update-motd.d/00-header, adding some color to make it easier to read: printf "Welcome to \e[1;34m%s\e[0m \e[2m(%s %s %s)\e[0m\n" "$DISTRIB_DESCRIPTION" "$(uname -o)" ...
2
votes
1answer
45 views

How to simulate user interaction when running another script

I am new to shell scripting. When I want to run a bunch of Linux commands I do fine, but how do I give user input when another script is called and asks for input while it runs. Here is the situation ...
5
votes
2answers
168 views

if statement in .bashrc not working correctly

I set up .bashrc to show a long prompt if the terminal is at least 80 characters wide. Otherwise it shows a degraded, smaller prompt. I use an if statement to achieve this: dp_smaller_than=80 if [ ...
2
votes
4answers
115 views

How to initialize an array using awk and bash?

I am trying to store values of the first line of a text file into an array. Here is what I have so far: arr_values=() awk ' NR==1 { for (i=0; i<=NF; i++) ...
5
votes
3answers
314 views

Is there any harm in using variables that aren't set?

Say I have the following code: # Check if the color prompt is enabled and supported on this system if [ -n "$force_color_prompt" ] && [ -x /usr/bin/tput ] && tput setaf 1 ...
7
votes
2answers
221 views

Cannot sum numbers received from stdin using bc

I'm trying to calculate the average entropy of files contained in a folder using: { echo '('; find . -type f -exec entropy {} \; | grep -Eo '[0-9.]+$' | sed -r 's/$/+/g'; echo '0)/'; find . -type f | ...
1
vote
3answers
36 views

How to run executable program with filter

I want to run a shell script. This script have a long name. So I want to use filter for file. ex: ls | grep myfile | ./ Is it possible to execute a file with filter.
1
vote
2answers
30 views

Start several fish shells in different directories?

In order to be able to launch my work environment with a single command, I want to start several urxvt windows running fish shell in different folders. However, I found no obvious way of having fish ...
1
vote
1answer
30 views

Kill all queued jobs

I need to kill all the queued and running jobs on my ID. I have tried at -l | awk '{print $1}'| at -r {} But I keep getting {} does not exist Which leads me to believe that I am parsing ...
5
votes
1answer
69 views

Why does `bash -c somecommand` sometimes not leave a bash process?

On an Ubuntu 12.04, with GNU bash, version 4.2.25(1)-release (x86_64-pc-linux-gnu), I tried the following command: $ bash -c 'pstree -s $$' init───sshd───sshd───sshd───bash───pstree $ bash -c 'pstree ...
6
votes
3answers
58 views

Can we configure different shells for different users on a single Linux/Unix distribution?

Well, this is not something that I want to do but I ask this question to know more about Shell configuration in Unix/Linux systems. So, the situation that I want an answer to is the following -: As ...
-16
votes
3answers
118 views

Which amongst the given option is TRUE about login shell?

Which amongst the given option is TRUE about the login shell? The login shell varies every time the user logs in. The kernel decides on the availability of the shell during login. The login shell ...
0
votes
1answer
70 views

Bash Script : Passing a variable to a bash script that contains quotes, single quotes. etc [closed]

lets assume this is the string: 'a',"b" it contains both single and double quotes. how would you pass this to a bash script as a single string ? this is the bash script: #!/bin/bash echo $1 ...
2
votes
2answers
98 views

“cat” command: how to automatically escape everything that might be a violation?

If you copy the contents of httpd.conf and then paste it into a cat command.. such as this one.. #!/bin/bash cat > /test << EOF pasted here.. EOF you run into this error: -bash: ...
0
votes
2answers
43 views

How do I sort using the grep and sort command

I would like to create a sorted list of all TCP services found in the file /etc/services. Pipe the output of the command grep tcp /etc/services into the command sort. Redirect the output of this pipe ...
2
votes
3answers
60 views

Can I chain pgrep with kill?

I have noticed that | is used to send results of first command to the another. I would like to kill all processes that match a name. This is what pgrep normally does: $ pgrep name 5089 5105 And ...
1
vote
5answers
46 views

grep for text that may or may not be present

Lets say I have a file batman; robin; superman; password = ""; wonderwoman green lantern if I want to check if there is a password present, i.e there is something entered in the "" . here is an ...
1
vote
1answer
29 views

Assign diff -y column names

I have two files and a shell script. File 1: Batman Superman John Snow Jack Sparrow Rob Stark File 2: Batman Ironman Superman Spiderman John Snow Arya Stark Jack Sparrow Rob Stark The hound ...
-2
votes
5answers
64 views

Resources to learn shell scripting [closed]

I have been using GNU/Linux for sometime now (Ubuntu and Fedora) and now I am trying to learn shell scripting from scratch. I would really appreciate if someone can guide me on choosing right ...
0
votes
2answers
94 views

Running system bash command in PHP script - syntax error: unexpected T_LNUMBER

If anyone can shed some light on my issue that'd be great. Please don't down-vote me; I'm new to the language and the OS itself and I'm trying my best to research before asking questions, so any ...
1
vote
1answer
44 views

Awk that I am stuck on

I have a project I am working on for work. The script I am building initially takes two arguments: one is an unique Identifier and the other is for a log file (both strings). Now I have the first part ...
3
votes
4answers
152 views

How to cut everthing until a specific word / after a find in a script

Hello I try to get the output of files from today wich contains ERROR. I use this to find the files I want: find /home/user/logfilesError/ -maxdepth 1 -type f -name "gandalf_*"\ -daystart -mtime ...
0
votes
2answers
18 views

Finding and replacing text inside awk block

I want to find and replace a value inside awk block. Here is a sample input file to my script P1 10,9:11/18013013582 ,10:1 ,167:0 ,487:5/E.164 11,9:15/310410532169026 ,10:60 ,167:0 ,487:4/IMSI ...
2
votes
1answer
486 views

bottomless tee?

I was just playing around in the terminal and I did this: printf 'some string\n' | { tee /dev/fd/3 | { : && sed 's/some/string/' } } 3>&0 I was really surprised when ...
7
votes
3answers
165 views

Local, timestamped logging of all ssh commands?

How can I keep a local, timestamped record of all remote commands I use in ssh (command-line openssh client started through bash)? Requirements: Essential: 100% client-side without relying on ...
1
vote
3answers
410 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 ...
3
votes
1answer
91 views

Rename files with spaces in a BusyBox shell

I'm trying to rename some files on my Synology Diskstation via SSH. The available shell is the BusyBox built-in shell: BusyBox v1.16.1 (2013-04-16 20:13:10 CST) built-in shell (ash) The move ...
6
votes
2answers
345 views

Array in unix Bourne Shell

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

How do I cat a command file?

I have the output of the crontab -l stored in a file (crontab_file) with no extension. But whenever I try to cat it, I get errors saying command not found for multiple line of the file. Here is the ...
3
votes
2answers
65 views

Gzip large amount of symlinked files

I have a folder containing a large amount of symlinked files. These files are each on the order of 10-11GB (fastq files to be specific). They come from a variety of source folders, but I made sure ...
1
vote
6answers
79 views

Is there a way to find out the number of lines from a command output?

I am trying to compare command outputs between two servers. I want to find out the number of lines from the output of commands such as ls -l. Is there a way to do so? So far I have not found anything. ...
2
votes
1answer
46 views

History in the Almquist shell in the NetBSD

In NetBSD /bin/sh is a modified version of the Almquist shell. With the command fc -l it is possible to view the last 16 commands typed in the prompt in the current session and not the older ones. ...
2
votes
1answer
33 views

stdout is empty

When a run the command: cellprofiler --get-batch-commands "/users/pmrotem/CellProfiler/example_project/output/Batch_data5_8.h5" in the shell, I get an output: CellProfiler -c -r -b -p ...
4
votes
3answers
113 views

zsh's “echo SomeText >> **/filename” in other shells

I need to fill all files with a specific filename (recursively) with a text. In zsh this can be done with echo SomeText > **/TheFileName I search generic solutions for sh-compatible and/or tcsh ...
3
votes
4answers
78 views

Protected environment variables?

Are there names of environment variables that cannot be overwritten by the user/a call to setenv? As I understand from POSIX1.2008, any process may edit the environment block, but must avoid ...
1
vote
1answer
53 views

Getting the parent path from a script

I have a bash script foocaller, which calls a ruby script foo: foocaller /path/to/foo Within foo, I want to get the path of foocaller. Following this suggestion, I put the following code to do ...
28
votes
3answers
2k views

What does `{ { (exit 1); exit 1; }; }` mean?

I quoted the next code snippet from config.status generated by configure. if test ! -f "$as_myself"; then { { echo "$as_me:$LINENO: error: cannot find myself; rerun with an absolute path" >&5 ...
-1
votes
1answer
27 views

Make an alias that does an alias command

I have to make an alias that will do the alias command. It has to "replace" the alias command and the user has to feel no difference..
4
votes
2answers
97 views

Execution order with multiple commands

I'm relatively new to Linux and I'm working on a CronTab for scheduled backups. I figured out how to do multiple sequential jobs with ; and &&, but I'm unsure how the dependency affects the ...
2
votes
1answer
42 views

How to move a window to a different workspace using its ID, in bash?

Currently I have successfully used wmctrl -r :SELECT: -t 2 but something like wmctrl -r -i 0x03e00003 -t 2 does not work. How should I write the command in order to select the window to be moved ...