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)

1
vote
3answers
338 views

How to make the shell execute only external echo, not the builtin one?

I have a C program which uses system() library function. Below is the source code. #include<stdlib.h> int main() { //Some code system("echo Hello World"); //some code return 0; ...
2
votes
3answers
526 views

Why are file names surrounded with “â” sign?

After adding alias rm='rm -i' to my ~/.bashrc file (because, when I removed a file, it wasn't asking for confirmation), file names are surrounded with "â" signs as in the example below: rm: cannot ...
0
votes
1answer
74 views

ssh pass multiple values

I want to open some ports i do for i in centos7{3..4};do ssh -T $i "for ir in 53 80 443 3000 3306 5910-5930 5432 8140 8443 10090-10100 20 21;do firewall-cmd --permanent --zone=public ...
1
vote
2answers
66 views

Gnuplot Shell Script

I was making this shell script to become faster in plotting data with gnuplot. It is the first s.s that I write so I'm having some difficulties. All was good until I started to make the if statement. ...
1
vote
1answer
41 views

Difference between $OPTIND and $#

Hey is there any difference between $OPTIND and $#? Is there a certain reason for that you use $OPTIND with getopts, not $#?
0
votes
0answers
88 views

irexec not starting at boot - LIRC

This code is in a shell script that starts up on boot /usr/bin/irexec /root/.lircrc -d The other sections in the startup script work, so the script runs ok. When the command is executed manually ...
-1
votes
2answers
82 views

killall fails some time

Hi below is the script which is intended to kill all instances of the process "processName" but sometimes it is not able to kill the process and we see double instance of the same process how can I ...
8
votes
2answers
288 views

Test for array support by shell

Is there a concise way of testing for array support by the local Bourne-like shell at command line ? This is always possible: $ arr=(0 1 2 3);if [ "${arr[2]}" != 2 ];then echo "No array support";fi ...
1
vote
1answer
77 views

How to take snapshot of website through shell script? [closed]

I have a website with login page. Now I want to generate a script to login into website and take snapshot of the screen through shell script. I'm using centos 7.1 . Is there any tool or utility to do ...
1
vote
3answers
198 views

Environment variable for command called via nice

I need to set an environment variable for a command that is being called via nice. [Bash and dash, Slackware and FreeBSD.] $ JIM=20 nice -n 10 echo $JIM $ Nope, echo can't see JIM $ nice -n ...
1
vote
0answers
32 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
2answers
49 views

Extract keyword from line

I need to extract similar patterns from data below. The pattern starts with '.' or '' then to the keyword I want, then followed by ''. We can assume the format is LSUFE-numbers_ PCRF-numbers_ ...
2
votes
2answers
65 views

Get path of here document as a file

I have a program that takes input from an XML file whose path is specified as a parameter. I want my shell script to be self contained, so a here document seems like the right way to go. ...
3
votes
5answers
3k views

Bash script: check if a file is a text file [closed]

I am writing a menu based bash script, one of the menu options is to send an email with a text file attachment. I am having trouble with checking if my file is a text file. Here is what I have: ...
4
votes
5answers
5k views

How to read certain lines after a find some text?

How i can read a certain number of lines after find some text? Eg.: Read next 2 lines after find "Unix" on: Test 1 Test 2 Test 3 Test 4 UNIX Test 5 Test 6 Test 7 Test 8 Test 9 Result can be: ...
0
votes
2answers
81 views

Why is my shell variable concatenation not working on ubuntu bash?

I am unable to explain the below behavior. Any ideas ? Welcome to Ubuntu 12.04.5 LTS (GNU/Linux 3.13.0-32-generic x86_64) * Documentation: https://help.ubuntu.com/ New release '14.04.2 ...
48
votes
3answers
23k views

Quoting within $(command substitution) in Bash

In my Bash environment I use variables containing spaces, and I use these variables within command substitution. Unfortunately I cannot find the answer on SE. What is the correct way to quote my ...
2
votes
1answer
72 views

are there any other shells than bash/dash which are used used as default in GNU/Linux distros?

Debian/Ubuntu use bash/dash and while you can use and have access to other shells, they don't work well with the kernel, so for booting up purposes, you have to have bash/dash. Are there any other ...
4
votes
3answers
204 views

Leap year - extrapolating value

I have some tables (table.txt) as follow: YEAR MONTH DAY RES 1971 1 1 1345 1971 1 2 1265 1971 1 3 1167 The length of each time series goes from 1.1.1971 until 31.12.2099. ...
2
votes
2answers
140 views

Conditional execution block with || and parentheses problem

So this should be simple. I am trying to test a condition at the top of a script and bail out of the entire script when the condition fails, and I have two statements I want to execute when I bail. ...
1
vote
1answer
156 views

Changing a Users Default Shell

I have created a simple C shell on my local Linux server. I am trying to learn how to change the default shell of another user (bob) to be this new C shell that I have created. Is it possible to ...
3
votes
2answers
1k views

wait does not wait

If i have a file called myprogram containing sleep 200 date Run this in the background: $ sh myprogram & i want to know when myprogram has completed by using wait command $ cat >notify ...
4
votes
3answers
4k views

permission issues while doing ssh setup in cygwin

I'm trying to setup ssh-host in cygwin. Getting the below error: *** Warning: The permissions on the directory /var are not correct. *** Warning: They must match the regexp d..x..x..[xt] *** ERROR: ...
4
votes
3answers
143 views

Use terminal-based documentation effectively (no web browser) [closed]

The problem I was trying to find shell scripting information without an Internet connection, i.e. via man page. Specifically, I was looking how to pass and use parameters. man bash does not contain ...
0
votes
1answer
94 views

How to list all the alias for all the user have on my linux box from root [closed]

I have been trying to check the alias the all the user can possible have on my system, I am using root. There is any command that can list them?
0
votes
1answer
146 views

c shell script: find the directory and rename it

i am still new in this shell script. I have a task that given to me which i have difficulty to execute it. The task is i have a lot of directory which is based on ddmmyy. 03Mar2014 08Aug2013 ...
6
votes
2answers
4k views

Obtain exclusive read/write lock on a file for atomic updates

I want to have a file that is used as a counter. User A will write and increment this number, while User B requests to read the file. Is it possible that User A can lock this file so no one can read ...
1
vote
1answer
74 views

Rsync over custom shell with fifo

I'm trying to use rsync over a custom shell created with fifo. However I cannot find a way to deal with it : The script initsh to simulate a standard shell by fifo : #!/bin/bash rm fin mkfifo fin ...
4
votes
2answers
116 views

Are there shells that supports typed variables and multidimensional arrays?

Is there a shell that supports distinguishing between variable types? At a minimum, it should distinguish between Strings, Integers, Floats and Doubles. The following commands should be different. ...
0
votes
3answers
54 views

The fastest way to remove a string in a variable

Let's say I have a variable foo, that is: foo=`echo ab cd ef gh` If you echo foo, you get: $ echo $foo ab cd ef gh Now, I want to remove ef from $foo. What is the fastest way to do that?
0
votes
1answer
71 views

ln -s removes part of a file name, when filename is passed as a variable

I use a script to link some of the files I download to a different directory. When there are "-" in the file name, ln - s wont read the path correctly, even though the variable will be logged ...
9
votes
1answer
584 views

Is “wait &” (“wait ampersand”) a useful (bash) shell / shell script idiom or technique?

I've "inherited" some shell scripts for Linux machines running the GNU "bash" shell. In one particular case, the machine runs GNU bash version 2.0.5b One of those scripts has a wait & ("wait ...
1
vote
0answers
83 views

Check whether a process is running in privileged mode

I want to check if a specific process is running in privileged mode. If a process is running is privileged mode, necessarily the user running it is going to be root? I've noticed that when I use ...
2
votes
3answers
99 views

Check to see if a word is used before aliasing

I was thinking of making a new alias but it seemed like something that might be defined (aliasing git status to status yes I am that lazy.) I tried running status in terminal (Ubuntu Precise) and the ...
1
vote
0answers
26 views

Various environments and weird less behaviour [closed]

I am playing with I/O redirection and have problem with less behaving differently in two environments. Both environments are Solaris-based and are of the same version. I am executing program in two ...
4
votes
3answers
1k views

Permanently switching to zsh in a script, without being root and without being asked for the password

Is there any way to run chsh -s /bin/zsh without being root and without being asked for the password? I want to put it into a non-interactive script that isn't called by root.
3
votes
3answers
116 views

Why are square brackets preventing shell expansion?

'4800483343' is a directory, and 'file1' & 'file2' are two files in it. Why is the following happening? $ ls 4800483343 file1 file2 $ md5sum 4800483343/* 36468e77d55ee160477dc9772a99be4b ...
2
votes
3answers
47 views

need to move files with name into directories with corresponding names

I have files named patient_sample_L001_R1_001, patient_sample_L002_R1_001, patient_sample_L003_R1_001, patient_sample_L004_R1_001 another set named patient_sample_L001_R1_002, ...
10
votes
2answers
711 views

How to redirect the output of a command to an already existing file without deleting its contents? [duplicate]

I am making a backup of some files and am creating a checksum file, checksums.txt, to later check the integrity of my data. However pasting each checksum manually into the file is inconvenient since ...
151
votes
3answers
10k views

Why not use “which”? What to use then?

When looking for the path to an executable or checking what would happen would you enter a command name in a Unix shell, there's a plethora of different utilities (which, type, command, whence, where, ...
3
votes
2answers
156 views

Bypass a nawk snippet if the input file is empty

I have a script which generates several output files and use these output files during runtime. Following are the some of the files generated by the script: apple.txt, section_fruit_out.csv, ...
4
votes
1answer
119 views

mv overwrites read-only file without prompting

The GNU Coreutils manual for mv says: If a destination file exists but is normally unwritable, standard input is a terminal, and the -f or --force option is not given, mv prompts the user for ...
2
votes
2answers
128 views

To get logs in between particular time-stamps using shell script

I want to extract infromation from logs using a shell script for a particular time range . A line in logs looks like this: [14:58:27:176][15-10-2015]: testing1-vidya-Thu Oct 15 11:49:27 IST 2015 ...
0
votes
1answer
50 views

To get logs in between particular time-stamps along with date using shell script [duplicate]

I want to extract infromation from logs using a shell script for a particular time range . A line in logs looks like this: [15:01:27:176][15-10-2015]: testing1-vidya-Thu Oct 15 11:49:27 IST 2015 ...
1
vote
1answer
94 views

How to do float operation in Shell script? [duplicate]

time_value=$(($large / 1000)) $large could be 60 or 57. I'm expecting 57/1000=0.057. But I'm getting 0. So, is there any way to do this?
3
votes
4answers
1k views

pure shell complex substitution in variable

However it may be impossible, I hope I'm just bad man reader =) Is there any way to substitute text in variables on several patterns at time or even using back reference? For example, I have ...
-1
votes
1answer
66 views

How to write a Shell Script to find Inputs/Output of a Function in a given file

I need to write a shell script which tells us all function names in a given file and their inputs/outputs For Example consider the below file which has 2 functions. Each function has their input and ...
43
votes
9answers
80k views

How can I run a cron command with existing environmental variables?

How can I run a cron command with existing environmental variables? If I am at a shell prompt I can type echo $ORACLE_HOME and get a path. This is one of my environmental variables that gets set in ...
3
votes
1answer
134 views

Trap handling and implicit subshells in shell scripts

Let's say you have a shell script that runs some sort of cleanup code via an EXIT trap, like this: #!/bin/bash mytrap () { echo "It's a trap!" >&2 } trap mytrap exit echo I am at the end ...
3
votes
4answers
354 views

Comparing each file in two directories and copying it to another if it differs from its counterpart

How can I compare all files in two directories and copy the ones that are different to another directory? For example, say we have dir1 and dir2: dir1: build.gradle gradle.properties ...