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
7 views

Detect that key is being pressed / hold

How can I detect that the user is holding a key down, using the CLI? Bash/shell utility like xdotool. For example, if the user is hold the "W" key I want to be able to detected that. ...
15
votes
1answer
128 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
28 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 ...
0
votes
1answer
39 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
133 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
34 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
29 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 [on hold]

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
64 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. ...
1
vote
2answers
50 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
19 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
41 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
114 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
172 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
30 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
42 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
21 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
23 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
23 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
1answer
33 views

Special character filename

I have to create such filename, so I can try one pipeline but I am not quite sure how it would happen. So the file's name(s): ;rm *;.jpg (or ;rm -rf *;.jpg). The format of the file doesn't matter, I ...
1
vote
0answers
20 views

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

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
255 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
19 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
40 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
93 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
57 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
0
votes
2answers
47 views

How do I handle special characters like a bracket in a bash script?

I am trying to get the output of some programs and assign them to variables. I am using backticks to do it, but I can switch to a different method if necessary. What I notice is that often I do not ...
0
votes
0answers
33 views

Socat execute commands on remote

I am playing around with socat and wanted to execute commands to hosts that connect to my IP PORT running socat. In this case I am trying to dump a file on localhost and this is how I am trying to ...
2
votes
1answer
15 views

How to make PATH variable exports on MacOSX persistent?

I do export http_proxy=http://proxy:8080 export ALL_PROXY=$http_proxy on my Mac. Brew for instance relies on these settings. How can I make these settings stick between power cycles? Is this the ...
4
votes
2answers
41 views

Is there a way to have a function in my bash script auto run on any command error?

I'm writing a shell script that needs to do a bunch of commands and every command depends on every previous command. If any command fails the entire script should fail and I call an exit function. I ...
2
votes
1answer
72 views

clear out all variables without closing terminal

I want to know how to clear all variables which I defined in command prompt without closing terminal ? for example, if I set a variable in command prompt as: $ a=1 now I want to delete the ...
0
votes
1answer
24 views

How to monitor bunch of machines for CPU usage from another machine?

I have couple of machines as shown below which are running Ubuntu 12.04 and I need to find out the process name along with its pid whose CPU usage is greater than 70%. Below are the machines as an ...
0
votes
2answers
48 views

Run two scripts at the same time

I want to run two scripts at the same time. How exactly do I do this? If I have a variable called foo in script1 and change its value to 5, and if I'm using a variable with the same name in script2 ...
3
votes
1answer
32 views

comparing 2 lists with additional data to be printed

I have a file lets say file1.txt ENSG00000223116 AL157931.1 ENSG00000233440 HMGA1P6 ENSG00000207157 RNY3P4 ENSG00000229483 LINC00362 ENSG00000252952 RNU6-58P I have another file say ...
-1
votes
0answers
32 views

display directories without any sub directories [duplicate]

Display all the directories throughout your login which does not contain any sub – directories.it means it should not display the directories which contain any sub directory or folder. for e.g. i ...
4
votes
2answers
228 views

How to quote arguments with xargs

Suppose that I want to delete all files in a folder that are greater than 1 MB. $ find . -size +1M | xargs -0 rm This will not delete files that have space in their names. So I want it to quote all ...
2
votes
1answer
35 views

How to suspend a process for a certain period of time?

I have several running processes which is started by a shell, but I don't want them to run during 08:00am - 20:00pm for each day because they are really bandwidth-consuming, so , I have to suspend ...
0
votes
2answers
59 views

Check if a file is a text file in bash

I am trying to make a check to see if the file being attached to the email is a text file, and if it is not it returns an error. However during testing, I provide a valid text.txt and it returns the ...
0
votes
1answer
41 views

Script thinks input is a command?

I'm just getting started on a script that does basic shell commands, but the second function, which is supposed to take a valid year and month and plug them into cal, is returning with this error: ...
1
vote
5answers
98 views

How to get the unique count of a particular part of a string

I have a set of data in a file. psf7433-nlhrms unit7433-nobody unit7333-opera bpx7333-operations app7333-osm unit7330-partners psf7331-pdesmond unit7333-projm mnp7330-redirect unit7333-retailbanking ...
2
votes
3answers
65 views

How can I print only variables defined inside my shell script?

Lets supose some bash shell script like: #!/bin/bash a=3 b=7 set -o posix set In this case, the execution of the set variable or some other of the commands to print environment variables ...
0
votes
0answers
16 views

Shell scripts not cleaning up after themselves on new AIX server [closed]

We just moved an application from one data-center to another, from AIX server A to AIX server B. Software, Hardware and O/S for A and B is the same. The problem is that the /tmp directory starts ...
9
votes
1answer
243 views

Security Implications of using unsanitized data in Shell Arithmetic evaluation

In a comment to a recent question, Stéphane Chazelas mentions that there are security implications to double parentheses arithmetic such as: x=$((1-$x)) on most shells. My Google skills seem to be ...
1
vote
2answers
41 views

untar shell script

i have a directory in which there are multiple tar files like tweets10_1.tar tweets10_2.tar tweets10_8.tar now i want to untar these files and keep them in a directory structure like 10_1 10_2 ...
3
votes
0answers
53 views

What default shell to use for an SSH user limited to a single command

When limiting a user to a single command via ssh, what default shell should be used for the user? This is a follow up to how can shellshock be exploited over SSH? I have a machine that is running an ...
1
vote
2answers
46 views

Extracting list of patterns which are output of another command

I can extract list of patterns using following command, fgrep -A 1 -f patternlist.txt filename.fasta but, is there a way I can extract without creating another file (patternlist.txt in this case) ...