The shell is unix's command-line interface. You can type commands in a shell interactively, or write scripts to automate tasks.
3
votes
2answers
154 views
Limit stdout from a continuously running process
I haven't had much luck finding an answer to my problem, but maybe I'm not asking for it correctly.
I have a process I startup like the following:
nohup ping 127.0.0.1 > log.txt >2>&1 &
...
1
vote
2answers
42 views
How to strip directory structure with command line (or script)
I have a large collection of files packed into a two-level directory structure with many, many, many folders.
In other words, I have a folder with a great many subfolders in it. There are no ...
3
votes
1answer
634 views
A tee >( process ) is truncating its stdout when writing a file
When I use tee to pipe stdout directly to a "specific block of code" (which then writes the modified data to a file), I always get the full complement of exptected output lines in the file.
...
1
vote
1answer
81 views
stop processing in shell script but don't exit
I've got a script that I run continually to monitor vsftpd logs. Here is a small example:
#!/bin/sh
tail -n0 -F /var/log/vsftpd.log | while read line; do
if echo "$line" | grep -q 'OK UPLOAD:'; ...
14
votes
4answers
1k views
How to understand pipes
When I just used pipe in bash, I didn't think more about this. But when I read some C code example using system call pipe() together with fork(), I wonder how to understand pipes, including both ...
1
vote
0answers
67 views
Creating a terminal application from a shell script
I have a shell script. I want to convert the shell script to an application for Ubuntu which can be installed using (sudo apt-get install) command and after installing, the application can run from ...
2
votes
1answer
56 views
Why is `kill -s INT <zsh PID>` behaving differently from `Ctrl-C`?
Starting with:
% donothing () { echo $$; sleep 1000000 }
% donothing
47139
If at this point I hit Ctrl-C at the same terminal that is controlling the shell, then the function donothing does indeed ...
3
votes
1answer
125 views
Installing ksh as the standard shell in Redhat: Foolhardy?
I'm not a system administrator, but my organization is considering replacing /bin/sh in Red Hat Enterprise Linux 6+ with a hard link to /bin/ksh. How foolhardy would this be?
The background to this ...
0
votes
1answer
38 views
md5 String and File different
Why do I become a different hash when I try:
md5 <<< "Hello"
md5 -s "Hello"
Is it because of a possible line break in the first example?
3
votes
4answers
67 views
unzip file, which directory was created?
Objective:
After expanding archive a.zip by using command unzip on Ubuntu 12.10, assign the name of the folder a.zip expanded to to bash variable v.
a.zip is assumed and guaranteed to expand to a ...
1
vote
2answers
58 views
What do the bash-builtins 'set' and 'export' do?
I am at a bit of a loss as to the purpose of set and export in Bash (and I guess probably other shells too).
I would think it is for setting environment variables, but that can be done just with ...
4
votes
3answers
86 views
how to suppress bash octal number interpretation? (to be interpreted as decimal)
I have this:
date +"%H hours and %M minutes"
I use festival to say it up.. but it says like: "zero nine hours".. I want it to say "nine hours"!
but date always give me 09... so I wonder if bash ...
3
votes
1answer
118 views
Shell wildcards and dot files
I am a beginner terminal user trying to understand wildcards. I think I pretty much have a good grasp on it, but I have a couple of questions:
Why do the following two codes work as expected:
ls -d ...
5
votes
2answers
2k views
what is meant by connecting STDOUT and STDIN?
This is a newbie question. I'm reading a book, it says:
Every process has at least three communication channels available to it: “standard
input” (STDIN), “standard output” (STDOUT), and ...
8
votes
1answer
115 views
Output of command not in stderr nor stdout
I've stumbled on this issue, so I'm wondering how is this possible?
Standard run of command:
# zabbix_sender -c zabbix_agentd.conf -k mmysql.QCInserts -o 14
info from server: "Processed 0 Failed 1 ...
9
votes
4answers
699 views
Why doesn't “sudo su” in a shell script run the rest of the script as root?
A sample script can be as below:
#!/bin/bash
sudo su
ls /root
When using ./test.sh as the normal user, instead run ls as super user and exit, it switches to root; and when I logout, it executes ls ...
-4
votes
2answers
119 views
Redirecting the content of a file to the command “echo”
I have a file named my_file.txt whose content is just the string Hello. How could I redirect its content to the command echo?
I know I have the commands less, cat, more... but I need to do it with ...
2
votes
4answers
114 views
store and execute redirection/piped command in script
How do you store, and later execute, a command with redirection and and a pipe? (And is it the pipe, or the redirection, or both, that's causing my problem?)
I tried to print the urxvt version in a ...
2
votes
1answer
69 views
dircolors on zsh: Unrecognized keywords: MULTIHARDLINK, RESET & CAPABILITY
I am trying to get the solarized color theme to work in my terminal. I read the instructions here but I get the following dircolors error:
dircolors: `/home/avazquez/.dircolors_zsh':90: unrecognized ...
3
votes
1answer
136 views
Increase %e precision with /usr/bin/time shell command
When I run the time command in shell time ./myapp I get an output like the following:
real 0m0.668s
user 0m0.112s
sys 0m0.028s
However,when I run the command \time -f %e ./myapp I lose ...
13
votes
6answers
793 views
Can a Linux command have capital letter(s)?
Can a Linux command have capital letter(s)? I know it's supported but i want to be sure if it's a "problem" or considered "not a good thing"?
0
votes
1answer
69 views
Find all directories, in which user has access to search and echo this directories in shell
I need to find all directories, in which user has access to search(command find) and echo this directories in shell. USER is read from ksh.
for example:
read user
I know, if user want to use find ...
2
votes
3answers
89 views
Treatment of backslashes across shells
How do echo and printf treat backslashes in zsh, bash and other shells?
Under zsh I get the following behavior:
$ echo "foo\bar\baz"
foaaz
$ echo "foo\\bar\\baz"
foaaz
$ echo 'foo\bar\baz'
foaaz
$ ...
7
votes
5answers
736 views
Why is the terminal case-sensitive?
When I do - CD .. instead of cd ..
it gives me error saying -
CD: command not found
Why is the terminal case sensitive when it comes to linux commands? I mean you should be able to execute the ...
1
vote
1answer
65 views
how to setarch for each bash session
I am using bash as my default shell. I don't have root access. But I would like to customize my bash by setarch. So the question is how to do this automatically?
Currently, I have to manually run ...
3
votes
2answers
89 views
How to run "find -exec <script> {}\;
I have a script that changes the properties of the files for a folder.
Here is the example tree:
dir 1
--file 1
--file 2
--file 3
dir 2
--file 1
--file 2
dir 3
--file 1
...
3
votes
2answers
66 views
Read data from a pipe for a certain amount of time (in seconds)
Is there an easy way to create a pipe that only lasts for a given amount of wall time?
I want to be able to take a "snapshot" of what's being written STDOUT for a period of time (rather than bytes or ...
2
votes
4answers
110 views
Grep of many keywords over many files: speeding it up
I am currently facing a "performance problem" while using grep. I am trying to locate the occurrences of many (10,000+) keywords in many (think Linux kernel repository size) files.
The objective is to ...
2
votes
2answers
80 views
How do I escape a sub-directory name with an ampersand in it?
Running a kornshell and trying to traverse a directory tree.
Want to cd to a sub-directory named as follows:
-3ab_&_-3dc.img
My question is HOW do I need to escape the ampersand in this name?
...
3
votes
4answers
135 views
How to print “$” in here-document
How can I echo "$" in a here-doc in bash?
For example, I want to have a file with the content on remote server like $ABC=home_dir.
$ ssh hostname sudo -s <<EOF
echo "$ABC=home_dir" > file
...
4
votes
3answers
3k views
Simple Shell Script with Arithmetic issue… ** is giving me trouble
When I run this script I get this error:
./myscript.sh: 16: arithmetic expression: expecting primary: "1 ** 1"
When I run this shell script with bash, as in #! /bin/bash on the first line, the ...
5
votes
3answers
3k views
Processing bash variable with sed
Been banging my head off a wall on this
bash variable LATLNG contains a latitude & longitude value in brackets like so
(53.3096,-6.28396)
I want to parse these into a variable called LAT and ...
0
votes
1answer
64 views
Working of the [0-9] [duplicate]
I am learning the shell commands and came across the short tags eg.[0-9],[[:digit:]] etc.. As a proof of concept i tried deleting all the files with the rm command(i know its not a good practise but i ...
2
votes
2answers
87 views
Working of rm/ls with [0-9]
I am learning the shell commands and came across the short tags eg.[0-9],[[:digit:]] etc.. As a proof of concept i tried deleting all the files with the rm command(i know its not a good practise but i ...
5
votes
3answers
204 views
How do I remove all sub-directories from within a directory?
This question is kind of a phase II to the first question I posted at here
I have a directory that contains a bunch of sub-directories, .zip files, and other random files not contained within a ...
6
votes
1answer
141 views
What should interactive shells do in orphaned process groups?
(Re-posting in unix per the suggestion in http://stackoverflow.com/questions/13718394/what-should-interactive-shells-do-in-orphaned-process-groups)
The short question is, what should a shell do if it ...
5
votes
2answers
99 views
When is double-quoting necessary?
The old advice used to be to double-quote any expression involving a $VARIABLE, at least if one wanted it to be interpreted by the shell as one single item, otherwise, any spaces in the content of ...
11
votes
5answers
3k views
determining path to sourced shell script
Is there a way for a sourced shell script to find out the path to itself? I'm mainly concerned with bash, though I have some coworkers who use tcsh.
I'm guessing I may not have a ton of luck here, ...
2
votes
2answers
203 views
What is the difference between declare and typeset
Can anyone explain difference between declare and typeset with real life examples .
1
vote
1answer
62 views
Quoting curly braces in the shell [duplicate]
I found examples of different quoting for curly braces for find, but I could not find an explanation. The possible choices are:
1. {}
2. '{}'
3. "{}"
And they all seem to work fine. Is ...
1
vote
1answer
60 views
What rules govern the parent-child relationship of processes launched by shell across a pipe?
#!/bin/ksh
# start_service: start the service
my_server_executable 2>&1 | my_pipe_following_shell_script &
exit 0
After I run the above start_service script from command line, it is ...
8
votes
5answers
188 views
store command before pressing ctrl+c, revive afterwards [duplicate]
Sometimes I type a lengthy command in my command prompt and then notice that I need to check something before actually pressing return and executing the command. I press ctrl+c, execute the new ...
2
votes
1answer
60 views
Find out where $PATH got corrupted
I'm using OSX Mountain Lion 10.8.2
$echo $PATH prints this:
/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/opt/X11/bin:/Users/myusername/.rvm/bin
I've commented out everything in ~/.bash_profile ...
10
votes
3answers
383 views
What does ${1+“$@”} mean in a shell script, and how does it differ from “$@”?
In the Perl documentation, perlrun(1) suggests launching Perl scripts using a bilingual shell/Perl header:
#!/bin/sh
#! -*-perl-*-
eval 'exec perl -x -wS $0 ${1+"$@"}'
if 0;
What does ${1+"$@"} ...
5
votes
1answer
110 views
Find all users who have more than N processes and echo them in shell
I'm writing a script in ksh. I need to find all users who have more than N processes and echo them in the shell. N is read from ksh.
I know that I should use ps -elf, but how do I parse it, find ...
2
votes
2answers
98 views
Testing a string containing only spaces (tabs, or “ ”)?
My code below doesn't work:
stringZ=" "
if [[ "$stringZ" == ^[[:blank:]][[:blank:]]*$ ]];then
echo string is blank
else
echo string is not blank
fi
Result:
string is not blank # wrong
...
5
votes
4answers
329 views
Shell command to get all the files from a complex directory structure
I'm looking for a shell command in order to get all the files in a complex directory structure. By complex directory structure I mean that there's a root folder with more than 150 subfolders and for ...
17
votes
9answers
984 views
Bash commands inside vi
Is it possible to type a bash command inside vi and get the stdout?
I find it often tedious to close and reopen vi just because I want to look something up in the shell.
3
votes
1answer
97 views
How can I remove an element from an array completely?
unset array[0] removes the element but still if I do echo ${array[0]} I get a null value moreover there are other ways of doing this but if an element of an array contains spaces like below
...
3
votes
4answers
103 views
Replacing pattern after nth match is found on each line?
I have a file containing lines:
india;austria;japan;chile
china;US;nigeria;mexico;russia
I want to replace all the occurences of semicolon on each line with e.g. ;NEW;, but starting from the 2nd ...


