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)

7
votes
2answers
398 views

Bash - how to run a command after the previous finished? [duplicate]

Currently I have a script.sh file with the following content: #!/bin/bash wget -q http://exemple.com/page1.php; wget -q http://exemple.com/page2.php; wget -q http://exemple.com/page3.php; I want to ...
1
vote
3answers
111 views

ksh, perform action when reaching loop maximal value

I am looking to write a small korn shell script doing 5 tests (by waiting some time before each one) and then, if they all fail, performing an action. I was looking at doing something like : for ...
2
votes
1answer
48 views

Supply the same filename as argument to two commands [duplicate]

On a git conflict, I can currently do: git diff path/to/some/file.txt ... after reviewing the diff, usually I want to do: git checkout --theirs path/to/some/file.txt && git add ...
0
votes
2answers
9 views

Manually executing a CRON - Confused about params

I have this code snippet: $CUSER=tim $APPDIR=/var/www/testing $APPVENV=/var/www/testing/ven cat > $APPDIR/cronfile << EOF PWD=$APPDIR/$CUSER PATH=$APPVENV/bin:\$PATH 0 2 * * * testapp search ...
57
votes
8answers
60k views

How to add a newline to the end of a file?

Using version control systems I get annoyed at the noise when the diff says No newline at end of file. So I was wondering: How to add a newline at the end of a file to get rid off those messages?
0
votes
1answer
27 views

what is the difference betwwen starting a command with nohup and &? [duplicate]

nohub and & seem to have a similar effect on the surface, they both start processes without occupying the shell from which they have been started, how do they differ on a deeper level?
3
votes
2answers
33 views

How can I catch a command exit code for later, in a Makefile?

I have a makefile, with a test suite target, like so: rcheck: foo This shows the output from the foo command on stdout, and returns an exit code from foo which is handled by make as normal. ...
0
votes
2answers
29 views

is the shell a frontend to the terminal? [duplicate]

Is the shell only an addon to the terminal, so that a terminal daemon has to work in order to to start a shell as its frontend. What controll does the terminal exherts upon the shell?
1
vote
0answers
32 views

A way to distinguish between interleaved output from two background processes

If I have two backgrounded processes that produce input to STDOUT or STDERR (e.g., two installation scripts), is there an easy way to make these two output streams distinguishable? I guess I can pipe ...
52
votes
4answers
3k views

Why is `[` a shell builtin and `[[` a shell keyword?

As far as I know, [[ is an enhanced version of [, but I am confused when I see [[ as a keyword and [ being shown as a builtin. [root@server ~]# type [ [ is a shell builtin [root@server ~]# type [[ [[ ...
11
votes
3answers
5k views

When do you need 'nohup' if you're already forking using '&'?

First this question is related but definitely not the same as this very nice question: Difference between nohup, disown and & I want to understand something: when I do '&', I'm forking ...
8
votes
4answers
2k views

/bin /etc /lib64 /root /sbin deleted or moved by mv folder/* /* while su

OS is Centos 6.5 64-bit I downloaded a tar file and wanted to untar and mv it. I untared, then accidentally (as root) ran mv folder/* /* instead of mv folder/* . bash said it couldn't overwrite some ...
6
votes
2answers
201 views

Issue in Standard Output and Error [duplicate]

If I type cat > file.txt 2>&1 then file.txt is created with the content of cat's standard input.  But if I do cat > file.txt 1>&2 then file.txt is created, but the file is ...
0
votes
2answers
60 views

Help to read a flat file into unix and output to simplified csv like format for import into excel

I have a text file that has data written to it in the format below, its thousands of rows. The new record always begins with WHATEVER.RDNDISPLAY or WHATEVER.DSPLY_NAME. The name of the record is ...
6
votes
4answers
9k views

Split a file by line and have control over resulting files extension

There is a standard command for file splitting - split. For example, if I want to split a words file in several chunks of 10000 lines, I can use: split -dl 10000 words wrd and it would generate ...
3
votes
2answers
99 views

On Ctrl+C, kill the current command but continue executing the script

I have a bash script, wherein I execute a line, sleep for sometime and then tail -f my log file to verify a certain pattern is seen, I press ctrl +c to get out of tail -f and then move to the next ...
1
vote
3answers
145 views

The equivalent of cmd “for” in bash?

I'm a Linux newbie, and I only know little about bash (or any Linux shell - but I just use bash). I'm used to using for %c in (*.*) do {something} in cmd in Windows, and I really feel inconvenient ...
2
votes
1answer
46 views

Debian Linux: Start/run application/process in another virtual terminal

You'll have to bare with my my Linux terminology is pretty bad. When I say virtual terminal I'm talking about when you press ctrl+alt+ a function key (F1-F12). I think they are called virtual ...
0
votes
2answers
44 views

How to use variables properly in this little script?

Here is a little script to retarget old-wrong symlinks that I want to make interactive. #!/bin/bash # retarget (broken) symbolink links interactively echo -n "Enter the source directory where ...
0
votes
1answer
50 views

Command “>” failing in Embedded Linux only

I'm developing an app in Qt for Embedded Linux where I want to see how much (%) of the given partition is occupied. I found on the web that a way to do this would be by calling the df command passing ...
13
votes
4answers
1k views

How to do a continous 'wc -l' with gnu texttools?

I know of course that cat logfile.txt | wc -l 120 will tell me the number of lines in a file. Whereas tail -f logfile.txt will show me the new lines that another program writes to logfile.txt. ...
0
votes
2answers
41 views

How to add a column if line contains string?

If I have a tab-delimited file containing the following lines: Sample1-Baboon 1 2 3 4 Sample2-Human 1 2 3 4 Sample3-Human 1 2 3 4 Sample4-Baboon 1 2 3 4 How can I add a new column ...
1
vote
1answer
41 views

Display result of a command right aligned in terminal

I have a script that goes through many different checks and I use the success, failure functions defined in /etc/init.d/functions to clearly show the action result on the terminal. That works great, ...
2
votes
1answer
48 views

Equivalent of “which” in sh [duplicate]

I found out today while developing a shell script that which is not a builtin for sh. What is a good equivalent?
3
votes
1answer
540 views

KSH styling text based menu using STDERR

Is it possible to format the STDERR in order to have a better looking menu using the select command? I have a simple select select oChoice in $(<tempMenu.menu) ; do case "$oChoice" in ...
1
vote
0answers
31 views

Autocomplete issue in bash with equal sign (=)

I am trying to make autocomplete work and wroted a piece of code to demonstrate an issue I faced up: $ cat completion.sh function _completion_command() { compopt +o bashdefault +o default +o ...
0
votes
2answers
65 views

In a shell script, How to give a variable another value after one job is done?

I'm trying to make a script which will see if the directory exists and will zip all of its contents under it according to the name/path of the directory. The farthest I could go was - ...
76
votes
4answers
2k views

Can I somehow add a “&& prog2” to an already running prog1?

Most shells provide functions like && and ; to chain the execution of commands in certain ways. But what if a command is already running, can I still somehow add another command to be executed ...
1
vote
2answers
135 views

Perform multiple commands on one line

There are two steps, that I would like to be run on one line: twinkle -c then call sip:in06khattab@sip.linphone.org Here is the output: I wanted to perform these two steps on one line, I ...
1
vote
4answers
47 views

Dynamically reference a file's name

In a single directory, I'd like to replace the first line of each file with the file's name. Each file has as the first line "TestRelation." I'd like to replace it with the file's name. I know I can ...
1
vote
3answers
87 views

How to pass an array to a function as an actual parameter rather than a global variable

Is there a way to pass an array to a function as one of its parameters? Currently I have #!/bin/bash highest_3 () { number_under_test=(${array[@]}) max_of_3=0 for ((i = 0; ...
3
votes
3answers
136 views

How to rsync files between two remotes?

I would like to transfer files between two remote hosts using on local shell, but it seems rsync doesn't support synchronisation if two remotes are specified as follow: $ rsync -vuar host1:/var/www ...
0
votes
1answer
19 views

What is the meaning of “${name##*/}” in Shell [duplicate]

I have a code as while read name; do uuencode "$name" "${name##*/}"; done but I do not understand what is meaning of ##*/ in "${name##*/}" Google doesn't give good results. Can someone please ...
1
vote
1answer
30 views

Can .bash_profile be auto sourced after change?

I'm always wondering if there's a way to do this. I don't want to type source after changing my .bash_profile all the time.
0
votes
0answers
22 views

what is the meaning of “${x%*.*}” in shell? [duplicate]

While I am using the code as ${x%*.*} it is excluding the extension of the file. for e.g. $ x="file.txt" $ y="file.20150208.dat" $ echo "${x%\*.\*} ${y%\*.\*}" file file.20150208 But how this ...
35
votes
11answers
14k views

How do I reuse the last output from the command line?

This is a noob question, but I'd like to know how to reuse the last output from the console, ie: pv-3:method Xavier$ python -c "from distutils.sysconfig import get_python_lib; print get_python_lib()" ...
6
votes
3answers
6k views

How do I insert a space every four characters in a long line?

I've got a long line that I want to insert a space every 4 characters, on a single lone line of solid text to make it easier to read, what's the simplest way to do this? also I should be able to input ...
4
votes
3answers
79 views

Bash, insert last used argument of current command

I'm aware that you can recall the last argument of the previous command with !$ and also cycle through previous arguments with ALT + . but can you recall the last argument used for the current command ...
0
votes
1answer
30 views

Error while executing a.out from C shell

I am in my home directory. And there is an executable a.out in there. I want to execute it like- /bin/csh ~/a.out ^F^E@@@@@▒^A▒^A^H^C^D^B^B@^B@^\^\^A^A^E@@: Event not found. Its not that I cannot ...
0
votes
5answers
60 views

sed to replace with backspace

I have trail.txt, which contains spice netlist. Now I want to replace all expanded parameters to one line only i.e. remove + and append that line to previous line. trail.txt data + net06706 ...
0
votes
4answers
32 views

adding programs to path [duplicate]

I have a load of tools that are kept in the /opt directory. The tools are organised like this: /opt/toolname/tool.sh. My question is, how can I add the tools in my /opt folder to my path, so i can run ...
4
votes
4answers
1k views

Get vertical cursor position

This might sound pretty weird, but I know how to set the vertical cursor position in Bash like this: echo -e "\e[12H" This moves the cursor to the 12th line (starting with 1). So how do I get the ...
4
votes
9answers
726 views

Metaphor for the concept of shell?

I'm finding myself helping out some classmates in my computer science class, because I have prior development experience, and I'm having a hard time explaining certain things like the shell. What's a ...
3
votes
2answers
57 views

Loop over files returned from find?

I'm trying to piece together a script that recursively finds all the *.plist files in a directory and then operates on them. The script is below, but its producing unexpected results. The expected ...
1
vote
2answers
3k views

How do I sort using the grep and sort commands?

I would like to create a sorted list of all TCP services found in the file /etc/services, pipe the output of the command grep tcp /etc/services into the command sort, then redirect the output of this ...
0
votes
1answer
28 views

Running a “scheduled”/delayed script as sudo on server, via ssh - and right before ssh exit

This would have probably been answered by Keep running a script via ssh, if I didn't have to run a command as superuser. Let me try with an example: say on my server, I have this script as ...
1
vote
3answers
53 views

Shell script to find and count total number of characters in all the files

How can I make a script that finds every file in your home directory that is less than 3 days old and then gets a count of the total number of characters in all of these files?
0
votes
1answer
23 views

Can I treat all what I typed after a command as raw string?

I made a bash func for myself so I can through some words into a tree_hole file, it looks like this in bashrc: function th { echo -e "\n$@" >> /Users/zen1/zen/pythonstudy/tree_hole; } export -f ...
0
votes
1answer
60 views

How to know, when a shell command running in the backround getting killed or died

I am running a shell command which is invoking an avconv session. The command is running as a background process. When the script starts executing I am doing a curl post to a url with the created ...
1
vote
1answer
91 views

Set up graphic interface (desktop) for remote connection

I was assigned a CentOS VM that I manipulate through Putty. Everything I do to it is by command line so far, and I have admin rights to it. The VM is stored in the corporate data center served up by ...