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)

57
votes
7answers
74k views

Execute a command once per line of piped input?

I want to run a java command once for every match of ls | grep pattern -. In this case, I think I could do find pattern -exec java MyProg '{}' \; but I'm curious about the general case - is there an ...
3
votes
1answer
45 views

set -e in a subshell

I thought set -e had the same effect on subshells as on top-level shell. Apparently, it does not. This: ( set -e false true ) || echo false1 bash -ec ' set -e false true ' || echo ...
0
votes
0answers
13 views

My tcsh say “Unmatched” or “No directory or file found”

I have .csh script. When I want to execute it with source 8.csh Some times it says, no directory or file found some times it says unmatched. I realized another problem too. I can see 8.csh in ...
0
votes
1answer
16 views

Yakuake is not restoring my appearance settings

Yakuake is not restoring my appearance settings on startup. The settings are saved to disk, as far as I can tell with strace, is being read by Yakuake. However, Yakuake uses default settings ...
33
votes
8answers
15k views

How to make bidirectional pipe between two programs?

Everyone knows how to make unidirectional pipe between two programs (bind stdout of first one and stdin of second one): first | second. But how to make bidirectional pipe, i.e. cross-bind stdin and ...
3
votes
3answers
688 views

Forcibly create directory hard link(s)?

I understand the reasoning why nearly every unix version doesn't allow hard-linking of directories (in fact HFS+ on OS X is the only one I know, but even that isn't made easy to do yourself). However, ...
0
votes
3answers
4k views

The best way to add Unix Shell variables to CURL GET request

Let’s say I use curl –X GET command with the following link: “$WEBSITE_URL/ACTION_NAME/ACTION1;id=$ID?Command=TEST&id1=$ID1&id2=$ID2&id3=$ID3” As you can see, there are some $variables ...
23
votes
2answers
19k views

/dev/tcp listen instead of nc listen

With a netcat listener like: nc -l <port> < ~/.bashrc I can grab my .bashrc on a new machine (doesn't have nc or LDAP) with: cat < /dev/tcp/<ip>/<port> > ~/.bashrc My ...
-6
votes
1answer
49 views

How to determine current users who are logged in using a specific domain? | UNIX [closed]

I want to know How to determine current users who are logged in using a specific domain? For example, here is the question. Please tell according to it using the grep command and use of wc. ...
-3
votes
0answers
35 views

Outer loop stops without reading all lines of files when inside loop finishes in a nested while loop [closed]

I'm trying to use the below script to repeat actions to each line of the FILE. Inside the read while loop, I use another while loop to control the SYSTEM_COUNTER not to exceed MAX so that the system ...
-4
votes
0answers
24 views

How to determine current users who are logged in using a specific domain? [duplicate]

I want to know How to determine current users who are logged in using a specific domain? For example, here is the question. Please tell according to it using the grep command and use of wc. ...
0
votes
1answer
23 views

Copy folders has specific part of name and it is content

I have a long list of folder as follow: 001_bat_3513 002_mon_3213 003_bat_3515 004_btt_3540 005_bat_4513 055_bpt_8523 056_bot_3513 058_bat_1513 . . From this list: How can I copy the folders ( and ...
1
vote
2answers
41 views

Syntax Error near Unexpected Token in a bash function definition [closed]

Forgive me; I'm pretty new to bash files and the like. Here is a copy of my .bashrc: alias k='kate 2>/dev/null 1>&2 & disown' function kk {kate 2>/dev/null 1>&2 & disown}...
1
vote
1answer
38 views

create listening port on IPV6 WITHOUT netcat

I wish to be able to listen to a port (eventually creating a bind shell) on an IPV6 address. I have tried using the netcat installed on the linux (debian) machine I am trying to bind. sadly it seems ...
3
votes
5answers
341 views

When I redirect the output of ls to a file, the filename is included in that file. How can I avoid this?

Observe: $ ls $ ls > list $ cat list list This appears to indicate that when ls is executed that the redirection into file list has already begun and the list file is already created. A fine ...
4
votes
2answers
77 views

How to use a special character as a normal one?

Many questions like 'How to type the double-quote char (")?' are being asked, and we don't want to clutter our community with the same answer (Type it as \" if not enclosed in 's, " if enclosed in 's.)...
1
vote
1answer
1k views

Cannot add startup service to openWRT from init.d

I have openWrt installed on a TP-Link TL-WA901N/ND v3. I don't have luci package installed because I don't have enough space, so I can only do thing via cli. What I'm trying to achieve is to create a ...
1
vote
1answer
41 views

“render” textfile with carriage returns (^M) and save output to file

I have a Python CLI program that runs for a long time and has a sort of progressbar, which basically prints some text in the loop without "\n" at the end, at the next iteration it prints "\r" to erase ...
1
vote
0answers
29 views

Save return value from a function in one of its own parameters

Function: Func1() { str1=$2 $1=$str1 } Call function: local var1 Func1 var1 "Helle World" echo $var1 I know this will work but I guess it's not very "pretty": Func1() { str1=$2 eval ...
1
vote
1answer
25 views

How to set which shell does Midnight Commander use?

As far as I know, Midnight Commander should be able to run different shells within it (the line second to the bottom). My question is, where/how can I configure which shell does mc use? Thanks!
4
votes
1answer
852 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
6
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
229 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
31 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
108 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
43 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
57
votes
4answers
21k views

Prepending a timestamp to each line of output from a command

I wish to prepend a timestamp to each line of output from a command. For example: foo bar baz would become [2011-12-13 12:20:38] foo [2011-12-13 12:21:32] bar [2011-12-13 12:22:20] baz ...where ...
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
94 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
234 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
193 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
24 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
41 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
48 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
46 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
470 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
84 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 ...