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)

4
votes
1answer
855 views

KSH styling text based menu using STDERR

Is it possible to format the STDERR in order to have a better looking menu using the select command? I have a simple select select oChoice in $(<tempMenu.menu) ; do case "$oChoice" in ...
5
votes
4answers
13k views

Cant ssh, connection terminates immediately with exit status 254

The most recent thing I remember is changing the soft and hard memlock ulimit to unlimited. Now I cant ssh into the machine. This is the ssh log. Authenticated to IP ([IP]:22). debug1: channel 0: ...
0
votes
0answers
30 views

How To Create Soft Links To An Entire Directory Structure Which Has Sub-Directories, Files Etc! [duplicate]

I'd like to: Create a soft link for a directory or file. But have a scenario where I need to create soft links, to a directory which has multiple sub-directories, files etc. I wanted to loop across ...
16
votes
9answers
30k views

How to compare to floating point number in a shell script

I want to compare two floating point numbers in a shell script. The following code is not working: #!/bin/bash min=12.45 val=10.35 if (( $val < $min )) ; then min=$val fi echo $min
7
votes
1answer
5k views

remove lines where a field's value is less than or equal to 3 - sed or awk?

I need to remove every line that has a value of 2 or less in the 8th field (column). My data looks like this: 12-31 Airport 189 379 41 49.70946503 -124.91377258 2 2880 30.8 01-01 ...
3
votes
1answer
232 views

How to count occurances of phrase in grep, ignoring case?

I need to search for a name nicolas bomber with grep. Name can also be NiCoLaS BomBer. I need to run a .sh file which display the number of occurrences of that name. The command I made is this one: ...
0
votes
2answers
33 views

How to delete files in directory

I have to delete one particular file in each directory. Can you help me with any shell script to do? Example: MKRUW, DKRUW, TKRUW In each of these directories I need to enter MKRUW/default/file and ...
2
votes
3answers
109 views

Writing an unlimited number of defined values into a file [closed]

I can use /dev/zero or /dev/urandom to write values into a file. Is there also a way to write an unlimited amount (just restricted by a command line switch maybe) of defined numbers (e.g. 1, 2, etc.) ...
8
votes
2answers
37k views

bash shell - ssh remote script capture output and exit code?

I wish to use shell to invoke a script on a remote server. I would like to capture the output of that script (its logging messages) and the exit code it returns. If I do this: ssh user@server /usr/...
0
votes
1answer
48 views

Script for automatic gateway switching

I have two network connections. If one goes down other should come up automatically how i can do it with a shell script in Ubuntu 12.04
0
votes
0answers
25 views

alias defined in modulefile does not work in launched shell [duplicate]

I am trying to get aliases working on my company's number crunching machine, which uses the bash shell on CentOS 7. For software management, we use GNU modules. Some case set-ups for certain ...
6
votes
1answer
103 views

Cannot exec /bin/false: no such file or directory

I'm trying to open GNU Screen with the following command on my Mac OS: host:~ user$ screen The screen terminal opens but quickly dies with the error message: Cannot exec /bin/false: no such ...
5
votes
4answers
7k views

Backup file with .bak _before_ filename extension

I commonly backup config files on servers without version control like so: # cp httpd.conf{,.bak} # ls httpd.conf httpd.conf.bak However, for files in the web root I take the time to carefully ...
2
votes
2answers
237 views

Dropping a process into the background

If I have started a process, and it spends more time than I anticipated, and I regret not having said rm foo & rather than rm foo, can I do something to drop it into the background?
0
votes
3answers
206 views

Check for process and kill if running

I am trying to find if a process is running or not, and if it is runing then I want to call a script or print something. I tried with the below few ways, but it gives me syntax error or command not ...
1
vote
1answer
37 views

copy a file to a destination with different names

I want to copy a text file to a directory with multiple names with curly braces: cp /path/to/file/a.txt /path/to/file/{b,c,d}.txt But it gives me the error: target '/path/to/directory/d.txt' is not ...
1
vote
0answers
40 views

unable to set GOPATH, despite beign set! [closed]

Edited: I found the reason! all of this was caused by an inapprotriate use of the sudo command while making directories and installing the GoLang language from the git repository. By using the ...
0
votes
0answers
20 views

Set variables into script before or after SCP [duplicate]

I have two scripts out and disk_check.sh. The main script is the out which exports multiple variables but I need two variables set in disk_check.sh which are: VOL and VM_VOLUME. So my out script ...
1
vote
2answers
26 views

Mail one liner to check if null before sending [duplicate]

I'm trying to modify a script which emails a user group the contents of a directory. The modification I'm looking for is to check the script below to see if it has valid output before sending. The ...
0
votes
0answers
42 views

Removing directories: Shell vs. File Manager

I've noticed that some graphical file manages such as Thunar allow you to remove any directory as long as you are the owner of this directory -- even if this directory contains a sub directory which ...
18
votes
4answers
17k views

Why is SIGINT not propagated to child process when sent to its parent process?

Given a shell process (e.g. sh) and its child process (e.g. cat), how can I simulate the behavior of Ctrl+C using the shell's process ID? This is what I've tried: Running sh and then cat: [user@...
2
votes
2answers
50 views

Bash function comments before or inside the function [closed]

Does the Bash language have a standard that dictates whether comments about the function should precede the function or be placed inside of it. I have seen scripts written both ways. # Comment ...
1
vote
2answers
95 views

what's the simplest way to increment the numbers in this string 01:02:99 in unix?

What is the simplest way to increment the numbers in this string 01:02:99? Expected output: 01:03:00 I'm hoping for a sed response, but I don't think it would be simple.
0
votes
1answer
48 views

`source …/settings.csh` not working from `sh ./test.sh`

I want to source Xilinx ise setiin64.csh file with the source command. I have source /home/xilinx/ise_14.5/14.5/ISE_DS/settings64.csh in another file, test.sh. So I want to run only test.sh file ...
4
votes
1answer
471 views

which bash is executing?

I think I have configured bash as shell, but why is this happening? My shell is bash: # ls -al `which sh` lrwxrwxrwx 1 root root 4 Jul 12 03:25 /bin/sh -> bash Error executing a script with ...
0
votes
3answers
25 views

Separating command arguments from flags

Say I have a command that takes flags and arguments, like this: mycommand --foo bar arg1 arg2 (The foo flag has a value of "bar".) But what if the foo flag can optionally be supplied with no ...
2
votes
1answer
85 views

Move all files into subdirectories named after beginning of file name

I have a directory that contains quite a lot of files with names made up of 8 random letters, numbers, _ and -, e.g.: 0dckGYH5.jpg 32Pz5-WQ.png 32_17pxH.png Hsf4BQW9.jpg xh-fa3Nu.gif zYtBEaKA.png ... ...
26
votes
13answers
11k views

Remove duplicate $PATH entries with awk command

I am trying to write a bash shell function that will allow me to remove duplicate copies of directories from my path environment. I was told that it is possible to achieve this with a one line ...
1
vote
1answer
48 views

is it possbile to add comma in this SQL?

I have a statement like this UPDATE `test`.`scores` SET id=1 name='kobe' score=99 WHERE id=1 name='kobe' score=100 UPDATE `test`.`scores` SET id=2 name='tmac' score=70 ...
37
votes
5answers
24k views

How can I make iconv replace the input file with the converted output?

I have a bash script which enumerates through every *.php file in a directory and applies iconv to it. This gets output in STDOUT. Since adding the -o parameter ( in my experience ) actually writes ...
3
votes
1answer
371 views

Delete all files with executable permission in a directory

I am in need of deleting all executable files from a directory. My directory contains some configuration files and executable files, and I need to delete all executable files that I don't want. For ...
2
votes
2answers
30 views

finding a folder names based on list contained in .txt file

I have a .txt file containing 150 different ID number on each line like so: 12345 15876 19643 12586 Located in the same directory as the .txt file, I have 300 folders and I want to copy only the ...
3
votes
3answers
898 views

Why dialog doesn't support emacs shell on Debian?

Dialog is a utility that provides dialog boxes from shell scripts, you may have seen them in aptitude during upgrades. When i use Emacs shell (M-x shell) and type sudo aptitude safe-upgrade, i get the ...
4
votes
5answers
409 views

Insert new lines with missing values (NA)

I would like to insert new lines in text files if there are missing values. I have for example the following text file (A.txt), for which line 5 is missing. In addition, as the file should have 12 ...
2
votes
2answers
46 views

efficient wait until NAS boots to mount it

Problem: Server boots 3 minutes, Raspberry Pi boots 30 seconds. After a power outage, RPi boots faster and does not mount the NAS disk. This particular RPi needs disk to be able to record to it. ...
0
votes
1answer
36 views

Why does my terminal say I'm running -bash (with a leading dash) and not bash?

I have recently started learning UNIX for a week or so and I've played around with the bash_profile and bashrc files to add in some basic preferences. But today, I couldn't execute several terminal ...
3
votes
2answers
101 views

How can I start several processes with a single command?

I use pianobar player. But before launching it I need to run tor and polipo. Both are continuous (are running until interrupted). Basically what I'm looking for is a single command which would spawn ...
4
votes
3answers
105 views

How to print same lines multiple times with variables changed using Sed/Awk/ anything?

a. Have set of lines as given below. cr_v8_sel0 : cross cp_v8_en, cp_sel0 { ignore_bins ig_v8_sel0 = binsof(cp_v8_en) && binsof(cp_sel0) intersect {[0:3],[5:$]}; } b. I wanted to print ...
1
vote
2answers
96 views

Escalate permissions through a background shell script

I would like to write to a Device File (of a printer) located at /dev/usb/lp0. The file is owned by lp user and group. This file is created whenever I connect my printer device to the system. I ...
3
votes
0answers
114 views

How can I run 'ls' with options from a C program? [migrated]

I want to execute the command ls -a using execv() on a Linux machine as follows: char *const ptr={"/bin/sh","-c","ls","-a" ,NULL}; execv("/bin/sh",ptr); However, this command does not list hidden ...
0
votes
0answers
19 views

How to change default shell on Solaris? [duplicate]

I am a user of a Solaris system which I log into as a standard user with no root or administrative privileges. The default shell for me appears to be bash. How can I change this to tcsh? I only ...
3
votes
2answers
87 views

How call a function inside another function

I'm working actually in a shell script to monitor a server's resources. I have a function and I want to know: how can I call a second function inside the main one? Example: funct mainfunct(){ echo "...
0
votes
3answers
58 views

Delete last line of gz file

I need to delete the last line of gz file without uncompressing. The file has 500 lines. How can I do that? I have tried: gzip -dc "$files" | tail -500 | gzip -c > "$files".tmp But It doesn´...
19
votes
3answers
40k views

How do I remove all sub-directories from within a directory?

This question is kind of a phase II to the first question I posted at here I have a directory that contains a bunch of sub-directories, .zip files, and other random files not contained within a sub-...
0
votes
2answers
1k views

bash: ./configure: no such file or directory

I am experimenting with Linux, and my work uses CentOS 6.5, so I am using that at home. I am following a tutorial, followed it closely I believe, yet I am hitting an error like the one mentioned in ...
51
votes
6answers
11k views

How to use `which` on an aliased command?

Like most users, I have a bunch of aliases set up to give a default set of flags for frequently used programs. For instance, alias vim='vim -X' alias grep='grep -E' alias ls='ls -G' The problem is ...
0
votes
0answers
12 views

How to recover a screen session?

I'm running a screen session and it seems it hung up somehow. 0 ✓ user@hoster ~ $ screen -ls There are screens on: 30418.pts-2.hoster (Detached) 1 Socket in /run/screens/S-user. However, when I ...
0
votes
0answers
55 views

What are the minimum required environment variables? [migrated]

I am writing a shell. With the execvpe system call, I can run a program and control its environment. What are the minimum values I need to pass through here? Alternatively, I understand that child ...
2
votes
3answers
4k views

How to remove element from the list?

I have written a command that output a list of hostnames, e.g. : clab148node11 clab148node12 clab148node15 clab148node16 Now, I would like to remove those nodes that do not respond to ping. For ...
0
votes
2answers
231 views

Why does this compound command report errors when copying directories?

If one executes the following two commands in one line as follows, rm -rf dir ; cp -r dir2 dir it may return that cp can not create directory dir/subdir: File exists but if these two commands are ...