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)

2
votes
3answers
22 views

What command(s) will feed a tab-delimited text file and cut each line to 80 characters?

I've got multiple-line text files of (sometimes) tab-delimited data. I'd like to output the file so I can glance over it - so I'd like to only see the first 80 characters of each line (I designed the ...
2
votes
1answer
12 views

Pipelines, Jobs and Processes in Zsh

I went through the Jobs & Signals documentation in Zsh, but some things aren't still clear to me. It says: If the MONITOR option is set, an interactive shell associates a job with each ...
1
vote
1answer
10 views

Get chronological list of dates & times an entry will run from crontab

Given a job specification in crontab, is there any way to get the list of dates and times the job in cron will run in the next week? For example, given a string 10 13 * * *, is there any way to get ...
2
votes
1answer
48 views

Why string comparision results always false

I am trying to do a one time check about apache's mod-status page for updates like this(this is just a test script): firstcontent=$(lynx -dump http://some-server/server-status-page) echo ...
2
votes
1answer
56 views

Problematic bc calculation in shell script

On Ubuntu 14.04.1 64-bit LTS I am writing a shell script and if I define the start of the sequence used in the for loop with a variable instead of a constant I get really weird behavior and there are ...
0
votes
2answers
30 views

Bash Script Parsing Argument not working correctly

i have the following bash script (taken from FFmpeg) #!/bin/bash ################################################################################ # # Script name: MultiMedia Concat Script (mmcat) # ...
2
votes
2answers
26 views

Bash globs as non-file arguments. Example: apt-get remove pkg-*

I know * and other glob patterns are transformed into words by pathname expansion, based on the current working directory. Hovever, some commands seem to use them for non file arguments. For example, ...
0
votes
1answer
18 views

if statment on installed script in sbin failing

I have a simple block of code that seems to fail and I'm not 100% sure why, if ! -h /usr/sbin/gitploy; then curl https://raw.githubusercontent.com/jeremyBass/gitploy/master/gitploy | sudo sh -s ...
2
votes
6answers
253 views

Print first and last line of all files in folder

I have a bunch of log files that get overwritten (file.log.1, file.log.2 etc). When I copy them from the device making them onto my local machine I lose the original time stamps. So I'd like to put ...
1
vote
1answer
33 views

Equivalent command for ``time`` for memory usage?

by using time we can easily get the information about how long a program run, I was wondering if there is any equivalent command I can use for memory usages? Like how many memory are allocated for ...
2
votes
2answers
44 views

Use config file for my shell script

I need to create a config file for my own script: here an example: script: #!/bin/bash source /home/myuser/test/config echo "Name=$nam" >&2 echo "Surname=$sur" >&2 Content of ...
1
vote
2answers
36 views

Creating a list of files, removing “duplicates” with different suffix

I have a problem that (I think) require a bit of script-magic - not sure what would be best though... I have one directory with lots pictures in different formats - jpg, gif, png, tiff and svg. Some ...
-4
votes
1answer
34 views

What is “jobs” commmand in Redhat Linux [on hold]

What is jobs command in Linux and how to use it? Please give some example.
1
vote
2answers
63 views

Is there a reason to quote the exit status $? variable?

I was looking at Google's style guides for their bash scripts, and saw that they quote the exit status variable $? here. if [[ "$?" -ne 0 ]]; then error_message fi I thought return values are ...
5
votes
4answers
314 views

Remove next-to-last extension in a file name

Suppose a folder with many files with bad extensions,for example Song1.avi.mp3 Song2.avi.mp3 Song32.web.mp3 Song23.mp4.mp3 Song2a.mp9.mp3 I want to remove only the second field (web, avi, mp4). I ...
-1
votes
2answers
18 views

How to compare strings in Bash script [on hold]

I have one strings like "9999991385" now I want to match first 4 digits from one file if it's match or not ??
0
votes
1answer
21 views

Why doesn't this tee with process substitution produce the 1st and chosen lines? [duplicate]

What I want is printing the output the first line ( table head ) of ps aux and the grep result. After search, I come up with following. ps aux | tee >(head -1 > /dev/tty) | grep mongo But I ...
1
vote
3answers
55 views

looping a command without waiting for the first run

I want a better way to do this, mostly for command line use: while sleep 60; do mysql -e 'show processlist'; done This is better than: while mysql -e 'show processlist'; do sleep 60; done ...
4
votes
1answer
72 views

How is ksh93 so fast?

So, in general, I tend to look to sed for text processing - especially for large files - and usually avoid doing those sorts of things in the shell itself. I think, though, that may change. I was ...
1
vote
2answers
59 views

How does bash's arithmetic work?

read num1 2 read num2 5 echo "$((num1+num2))" 7 echo "$(($num1+$num2))" 7 I referred this. I don't understand how the above both expressions yields same result? Please explain. echo ...
0
votes
0answers
32 views

Parameter passed to Shell script is not getting populated under printf command [on hold]

I am calling a script and building html table out of it. The val1 which i am passing is being captured in variable cluster. But its not getting printed in output. sh script.sh val1 > out.htm ...
2
votes
1answer
27 views

apt-get update exit status

How check the status of apt-get update? $ apt-get update ; echo "status is: $?" Err http://security.debian.org stable/updates Release.gpg Could not resolve 'security.debian.org' Hit ...
24
votes
3answers
478 views

Switch to parent shell without logging out

Let's say I start in my local account: avindra@host:~> then I switch to root: host:~ # Then I switch to oracle: [ oracle@host:~] Is there a way for me to drop back into the root shell (the ...
1
vote
1answer
32 views

why does grep '\;.' expand to grep '\''\;.'\''' when executed over ssh?

$cat test.sh ssh HOST -l root -o StrictHostKeyChecking=no -q "/bin/bash -l -c /bin/env | grep -w PATH | grep '\;.'" $bash -x test.sh + ssh HOST -l root -o StrictHostKeyChecking=no -q '/bin/bash -l -c ...
1
vote
1answer
41 views

Preventing user from accessing parent folders [duplicate]

I have a user who I only want to be able to access /var/www/ucp/ (his home directory). I have executed the following command on the / directory, the /var/ directory and the /var/www/ directory: chmod ...
1
vote
2answers
136 views

How to change dir to the last directory?

I have very long directories list, like /dir/dir/dir/../../../../../../../../../.. ../../ ../../last dir Is it possible to change to the last dir immediately?
0
votes
1answer
38 views

Debugging with shell programming and cpp files?

I am having trouble understanding how my code is working. I am new to this project and never learned unix before. My coworker quickly showed me how to run the program but didn't explain how it worked ...
1
vote
0answers
33 views

pkill -P $ID working while kill — -$ID not

I was playing around with creating and killing process groups on linux ( ubuntu ) I am trying to kill a process group and am being driven crazy by the fact that pkill -P $ID works while kill -- -$ID ...
0
votes
0answers
10 views

pdf2swf give result blank swf [closed]

I need to convert pdf file into swf Command I've tried: $PDF2SWFcommand = "pdf2swf /pdf/file/unsecured.pdf -o /swf/file/output%.swf -f -T 9 -t -s storeallcharacters > /dev/null 2>&1 & ...
3
votes
2answers
72 views

Am I hitting a race condition in bash?

I have a script which compares the output of a command with the output of the same command as it was ran previously, it works most of the time, but every now and then it doesn't work as expected. ...
2
votes
2answers
55 views

Shell Script - number of minutes

Shell How can I write a shell script, using only shell features (and the date command), to output the number of minutes that have elapsed in the current day?
1
vote
2answers
24 views

Count and list down + advanced features

I have a few questions: I have listed the number of lines in the files in /group/book/four/word, sorted by the number of lines they contain using $ wc -l /group/book/four/word/*|sort -n ...and ...
0
votes
1answer
25 views

How do I suppress all email notification from cron for particular job?

I am scheduling the following shell script #!/bin/bash (echo open mailserver.nowhere.local 25; sleep 1; echo EHLO; echo quit)\ | telnet | grep "?Invalid command" if [ $? -eq 1 ]; then ...
-2
votes
4answers
44 views

How to ignore the lines starts with # using grep / awk

cat /etc/oratab #test1:/opt/oracle/app/oracle/product/11.2.0.4:N +ASM2:/grid/oracle/app/oracle/product/11.2.0.4:N # line added by Agent test2:/opt/oracle/app/oracle/product/11.2.0.4:N ...
8
votes
2answers
138 views

How can I conditionally pass a subshell through 'time'?

I have a setup script for a Vagrant box where I used to measure single steps with time. Now I would like to conditionally enable or disable the time measurements. For example, previously a line would ...
6
votes
3answers
190 views

sed with multiple expression for in-place arguement

I am trying to replace multiple words in file by using sed -i #expression1 #expression2 file Something 123 item1 Something 456 item2 Something 768 item3 Something 353 item4 Output (Desired) ...
5
votes
2answers
47 views

Merging/Combining 2 text files according to numeric field

I have 2 text files file_1: 14595|Age 35|Salary xx|Position ax|2013|Info 1|Info 2|Info 3|Info 4|Info 5 14649|Age 30|Salary xx|Position az|2015|Info 1|Info 2|Info 3|Info 4|Info 5 file_2: ...
1
vote
3answers
28 views

Moving files recursively if certain condition is met

I have the following directory tree: records/13/2014.12.16/00/05.mpg records/13/2014.12.16/00/15.mpg records/13/2014.12.16/01/05.mpg records/13/2014.12.16/02/15.mpg records/15/2014.12.14/05/25.mpg ...
-2
votes
1answer
31 views

Archive file with date-stamp [duplicate]

I want to move(archive) the multiple files from say directory /users/wahasan to /users/wahasan/old. The archive files should be autodated. files are of the format CHKBOI.pos, CHKUTI.pos, ...
0
votes
1answer
44 views

Create A Script That Responds To A Password Prompt

I'm writing a shell script that will respond to a prompt. For example, when I execute a file, the executed file will then prompt the user with this: Please enter the password: Then I want the script ...
0
votes
0answers
22 views

How to disable “Warning: Program '/bin/bash' crashed” message?

I'm using Kubuntu 14.04. When I exiting terminal emulator (konsole or yakuake) by doing something like kill -9 $$ it doesn't close, and saying: Warning: Program '/bin/bash' crashed. How could I ...
0
votes
1answer
24 views

Interactive shell in background inside another shell script

I have some problems when trying to run an interactive sh session inside a shell script. The inner sh process uses all the CPU and never terminates. To reproduce the issue simply create a file named ...
0
votes
1answer
27 views

gnome--terminal -e option not executing?

I want to open my terminal with some commands executed in it on bootup. So I wrote a script with following line in it: gnome-terminal --tab -t "MyPC" -e "sh -c 'firefox &;exec bash'" --tab -t ...
1
vote
0answers
22 views

POSIX compliant shell script not portable because of the tools used inside [closed]

I've written a script which runs in a strictly POSIX compliant shell without trouble on my machine but a buddy of mine couldn't execute it. It seems as if his machine has different versions of tools ...
8
votes
1answer
267 views

Echoing progress from a background process without hijacking prompt

Consider the simple script hello: #!/bin/bash echo 'hello world!' Now from bash if I try to run this in the background: $ hello & [1] 12345 $ hello world! █ <--- prompt is stuck here until ...
0
votes
1answer
20 views

How to create a file name for the pipeline to delete all files?

So I want to delete all files in my current directory using the following pipeline: ls | sed -rn 's/(.*)\.jpg$/mv -n & \1.jpeg/pi' | sh How to create a file, named so that running the above ...
1
vote
1answer
41 views

Controlling the terminal while in the middle of a pipe [duplicate]

Say I have 3 commands linked through pipes: A | B | C I would like B to output error messages to stderr and some progress to the terminal. If stderr is the same as the terminal, then that is easy: ...
1
vote
2answers
74 views

How to rename file in bash script one by one

I have loads of files which look like this: data1.csv data2.csv . . data(n).csv My use case is that when I will call my script it will change data1.csv to data.csv and remaining files as it is and ...
1
vote
4answers
103 views

Killing a shell script running in background

I have written a shell script to monitor a directory using the inotifywait utility of inotifyt-tools. I want that script to run continuously in the background, but I also want to be able to stop it ...
3
votes
1answer
58 views

How to redirect output while using a here document

How to redirect the output of below command in shell into logfile. sqlplus -s "/nolog" <<EOF conn / as sysdba @?/sqlpatch/19282021/postinstall.sql exit; EOF