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
2answers
32 views

Extract lines with specific dates and execute a command on each of them

I'm using a Google Drive command-line script that can return a list of files such as: Id Title Size Created 0Bxxxxxxxxxxxxxxxxxxxxxxxxxx ...
3
votes
0answers
31 views

Rename file with the name from a variable [duplicate]

I want to rename an image with the text in that image. For that I use an OCR and I try to store the name in a variable and use that variable in the mv command but I get mv: target ‘file’ is not a ...
8
votes
3answers
203 views

How can I list all shell variables?

Reading about this question: In zsh how can I list all the environment variables?, I wondered, how can I list all the shell variables? Also, does the distinction between shell variables and ...
2
votes
1answer
18 views

Default shell in Oracle Linux?

bash is default shell for Red Hat Linux Distribution. In the same way, what is the default shell in Oracle Linux? I tried to find this by executing [root@serverName ~]# sudo $SHELL But, I did not ...
1
vote
1answer
17 views

Switching shells for one cron job

Say I have the following in my crontab: * * * * * command1 -option A; command2; command3; etc. I would like cron to run the commands I have in that line with a specific shell. How can I do that? ...
2
votes
1answer
43 views

goto manual questions

Hey :) I am trying to understand the command goto from the historical Unix v6. I have some questions regarding the goto manual. Here you can find the original manual: ...
1
vote
3answers
53 views

Iterative Control Flow in Subshelled Script [on hold]

I have a shell script(A) that is being called by another script(B). In this script(A) I am creating some directories and moving some files as preparatory work for the rest of the script to work fine. ...
2
votes
1answer
16 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
17 views

Get chronological list of dates & times for scheduled tasks in cron

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
60 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
59 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
35 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
28 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
19 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
7answers
266 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
34 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
46 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
37 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
35 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
64 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
315 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
78 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
33 views

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

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
28 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
529 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
42 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
73 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
26 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
141 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
191 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
48 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
29 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
32 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
45 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 ...