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
0answers
17 views

Difference between “$@” and “$*” when passing arguments to bash function [duplicate]

I'm having hard time understanding difference between $@ and $* when passing them to functions. Here is example: function a { echo "-$1-" "-$2-" "-$3-"; } function b { a "$@" } function c {...
-3
votes
1answer
27 views

Help required in logic

I have a below requirement. I am validating one of my code-file using one utility in shell script and writing that Error,Warning messages to an output file. Now i need to write a logic like if i ...
0
votes
0answers
77 views

How to get the date of a particular format in unix?

I am having a log files which contains date format. On basis of the previous date format I need to grep Date format present in the logs Dec 1 , Nov 18 I write the query select to_char(sysdate-1, '...
50
votes
4answers
6k views

Is there ever a good reason to run sudo su?

To launch a root shell on machines where the root account is disabled, you can run one of: sudo -i : run an interactive login shell (reads /root/.bashrc and /root/.profile) sudo -s : run a non-login ...
3
votes
2answers
399 views

How to resume a suspended shell?

$ help suspend suspend: suspend [-f] Suspend shell execution. Suspend the execution of this shell until it receives a SIGCONT signal. How should I send a SIGCONT signal to a shell suspended ...
1
vote
2answers
119 views

bash script to rank files based on sorting the column

I'm a beginner in Unix platform. I'm trying to rank file based on the sign of the log2FoldChange multiplied by the inverse of the pvalue. input file = Gene baseMean log2FoldChange lfcSE ...
0
votes
5answers
245 views

How to use grep to extract file names at end of lines?

I have a log file which contains information such as output using ls *.CCD from directory /var/tmp/Person: -rwxr-xr-x 1 bv90 dkas 153698 Nov 18 13:08 WE994002.CCD I have many such ...
0
votes
2answers
40 views

AWK Using a Variable in an Equality Expression

A simplified version of my code looks like the following: declare -a DMN=(" " "200" "190" "180") NRL=3 runDHFiles() { awk 'NR>13 {if ($4==$DMN[$i]) print $1, $2, $3, $4;}' domain_all.dat >> ...
0
votes
1answer
80 views

how to get latest file in each dir

Is there a Unix command to get the latest file in logsarchive of each dir of /app/instance? In the example below, I have 5 folders in /app/instance: as_a, as_b, as_c, aunz, naeu and I need to get the ...
1
vote
1answer
275 views

How to find timestamp after 10 minutes in Linux

I want to find the time after 10 minutes using date command in shell.
1
vote
2answers
116 views

Shell showing weird characters for one user

Some time back I added an user on Debian X64 server, and instead of showing me the username when I ssh into the machine, it shows me weird characters as shown in screenshot below. Please note, it does ...
0
votes
2answers
88 views

Unexpected prompt in zsh

Can someone explain to me why I am getting this shell prompt when I'm in the /home directory, and how to get rid of it?  I am using zsh. I want it to display only the following: user@host ~ % but ...
10
votes
7answers
393 views

Check variable is an array in Bourne like shell?

In Bourne like shell which support array variable, we can use some parsing to check if variable is an array. All commands below were run after running a=(1 2 3). zsh: $ declare -p a typeset -a a a=(...
0
votes
2answers
55 views

Script not able to generate files for backup file

I'm new to shell scripting and I trying to write a script that: Prompts for a directory Loops through the directory If it find files it then backs them up using a function in the script Creates a ...
0
votes
0answers
40 views

Linux how to find and delete a paragraph in a log file containing a data stamp as yyyy.mm.dd

Need to find and delete a paragraph in a log file which contains a specific date. This is a type of an html file but need to read through a linux editor like vi. The entries are as.. ####### </...
0
votes
1answer
60 views

Why my shell scripts are dying?

Observation1 logic.sh #!/bin/bash #get system metrics #do stuff and echo it echo "put metrics" | nc $ip $port echo "Metrics $metrics" run_logic.sh #!/bin/bash while true;do sh logic.sh >> ...
4
votes
1answer
192 views

Script that Outputs the Average of Multiple Group lines, from a File

This is a "Small" portion of the file car_sales.txt that I am trying to extract information from (the full file has about 700 lines, with more vehicle brands than are listed here): first_name,...
-7
votes
1answer
2k views

Head and tail command

How can i do this exercise in unix? Create the following command: lshead.bash – list the first few lines of every file in a directory specified by the argument. This command should also allow options ...
0
votes
2answers
70 views

How to write “!” symbol between double quotes in bash? [duplicate]

I can't figure out how to write ! symbol in bash scripts when putting it in double quotes strings. For example: var="hello! my name is $name! bye!" Something crazy happens: $ age=20 $ name='boda' ...
1
vote
3answers
238 views

Is it possible to list all files starting with a letter, but not directories?

I need for my home assignment somehow to get a list of all the files starting with the letter F, I know of the command: ls F* But it also gives me directories, is it possible to only show actual ...
-3
votes
1answer
28 views

Output the result of a variable

I have an if statement and I want in one case to add one to a variable v and in the other case to a variable inv. I did the following v=$((v + 1)) and inv=$((inv + 1)) I want to outputs the results of ...
0
votes
1answer
41 views

Is there a shell script converter between rwx/rwt etc and the octal version?

I gone through the script echo 'rwxrwxrw-' | perl -ne 'BEGIN{sub conv{ chomp(my $ins=shift); my $k=0; for(my $i=0;$i<=8;$i++) { my $tmps = ( substr($ins, $i, 1) =~ /[rwx]/ ); $k+= ( $tmps*(2**(8-$...
3
votes
2answers
333 views

Shell valid function name characters

Using extended Unicode characters is (no-doubt) useful for many users. Simpler shells (ash (busybox), dash) and ksh do fail with: tést(){ echo 34; } tést But bash, mksh, lksh, and zsh seem to ...
0
votes
1answer
34 views

Syntax error for a script requiring 3 specific read variables?

I have to hand write responses to a script that is already given to me. The two sets of information I have to give an output for are if the variables that will be read are 3 3 3, and 20 3 5. I ...
4
votes
2answers
85 views

What is the right way to consistently mangle bash terminal?

I'm on OSX 10.11.1 and occasionally my bash terminal gets mangled. It often happens when I accidentally cat a binary file. The result can be seen on the image below. The output becomes weird, and I ...
29
votes
5answers
94k views

Shell script fails: Syntax error: “(” unexpected

I've been working on a script that automates setting up a development environment for Raspberry Pi development (step by step details that work are here). The script is linked in that article but ...
1
vote
5answers
52 views

awk: Can I find the occurrence of char in given string?

Is there any way to get following result? a c a c a c a a a a a a a a c c c a c 0 0 a c 0 a max a 2nd max c
3
votes
3answers
34 views

Check piped input on empty spaces and forward it

I want to pipe the output of one command to another script. In this other script I want to check whether the input was empty or just consists of spaces. If this is the case, I'll ignore it. Otherwise, ...
1
vote
3answers
76 views

Split multi paragraphed shell output to multiple variables

I am looking to split multi paragraphed shell results into different variables, Here's a sample output from sensors to illustrate acpitz-virtual-0 Adapter: Virtual device temp1: +41.0°C (...
10
votes
1answer
171 views

Why does a while loop stop after being suspended?

Why is it that using bash and suspending a while loop, the loop stops after being resumed? Short example below. $ while true; do echo .; sleep 1; done . . ^Z [1]+ Stopped sleep 1 $ ...
2
votes
4answers
249 views

Interactively add arguments line-by-line in bash

Sometimes it happens that I have a list of files or strings in the clipboard and want to paste it as an argument list in a bash shell: Example file list (only an example): createsnapshot.sh ...
7
votes
2answers
18k views

Good method to compare time?

I need to check for the current time and abort the script if it is not proper time of day I am supposed to run it. Also, if anyone else runs it, it should abort. For example: I need my script to only ...
13
votes
7answers
15k views

How to insert the content of a file into another file before a pattern (marker)?

File1 contents: line1-file1 "1" line2-file1 "2" line3-file1 "3" line4-file1 "4" File2 contents: line1-file2 "25" line2-file2 "24" Pointer-file2 "23" line4-...
2
votes
1answer
710 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 ...
0
votes
0answers
60 views

Lightdm - call script on shutdown

I configured lightdm to call the following cleanup-script. Here the corresponding line in the lightdm.conf: ... session-cleanup-script=/usr/local/bin/call.logout.sh ... Here the script, which is ...
1
vote
4answers
2k views

Bash: remove numbers (strip numeric characters) from string variable

I want to strip all numeric characters from a String variable, eg from: VARIABLE=qwe123rty567 to: echo $VARIABLE > qwerty I've search many posts but they either use sed to output to file/file ...
9
votes
3answers
3k views

How can I forward a already forwarded ssh key into tmux?

I'm connecting through SSH from a machine where my keys are stored, forwarding to a second machine, and then try to use the keys from within tmux. I appear to "loose" the forwarding when entering tmux....
6
votes
4answers
212 views

Substitute Column With Result of Command

I'm trying to find a way to quickly and efficiently replace a column value for every row in a file with the output of a command. I need to work on multiple files with about 500,000 rows each daily so ...
2
votes
3answers
164 views

Random number generation in Solaris?

What is the best way to generate random numbers in Solaris? I can not seem to find a good answer for this. Most results do not work in my environment. There is a variable or command RAND that seems ...
10
votes
4answers
1k views

Why is my program called “set” not being executed?

I've created a simple C program like so: int main(int argc, char *argv[]) { if (argc != 5) { fputs("Not enough arguments!\n", stderr); exit(EXIT_FAILURE); } And I have my ...
0
votes
0answers
23 views

shell script how to pass multiple arguments with a common name [duplicate]

I want to run myscript.sh in this way: ./myscript.sh -g 10.10.26.129 -n 10.10.24.0/24 10.10.48.0/22 n contains multiple arguments, and the number of arguments of n is undetermined. My current code ...
1
vote
1answer
59 views

check if row contains characters

I have file that looks like This row contains characters this row to *-=?§/ this is the lat row of the file how can i only print only rows that contains some characters aka all but ...
-1
votes
1answer
42 views

How to remove duplicate rows using awk while splitting file

I'm using awk in a shell script so I can split a file according to the 5th column. The code below is similar to the one I'm using: awk -F';' 'NR==1{h=$0; next} !seen[$5]++{f="FILE_"$5".txt";print h &...
5
votes
1answer
656 views

Upstart and bash function names containing “-”

I inherited some bash scripts where the author used "-" in the function names instead of the more normal "_" e.g.: function a-b { ... } Ugly but legal in bash. Problem is I sourced this inside an ...
0
votes
2answers
141 views

Shell script using function () not finding command

I'm learning shell scripting and I'm studying how to use function in the shell script. The script is suppose to run as a basic math calculator with two defined numbers by the user. It's suppose to add,...
1
vote
2answers
29 views

Displaying a Date Variable

I am very new to shell programming and have a question. What is the best way to display the date right after it says "Creation date and time: " echo "What is your name?" read name echo "##############...
1
vote
2answers
137 views

Random files selector in filesystem

Context : In order to test some backup process which are supposed to work all nights, i want to select a random files on a large amount of datas. (Around 7 millions of files. This is a NFS server with ...
0
votes
0answers
21 views

Opening files with exec [duplicate]

exec 3<file opens file on filedescriptor 3. Can I open a file without caring what filedescriptor it should be opened on and then learn what the new filedescriptor is?
3
votes
2answers
215 views

Outputting a string in the bottom right corner of the terminal

How do I output a string in the bottom right corner of the terminal?
-1
votes
1answer
471 views

bash - Read input line from file then delete

I have this bash script: #!/usr/bin/env bash DOMAINS=( '.com' '.co' ) while read input; do for (( i=0;i<${#DOMAINS[@]};i++)); do MATCH=$(whois "$input${DOMAINS[$i]}" | grep -oPa '^.*\b(...