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
1answer
113 views

Run bash script on startup in Linux Mint and open mate-terminal automatically

I'm new to Linux, so not sure how to do what I want. I have my_script.sh (executable, of course) like this: #!/usr/bin/env bash mate-terminal -e "bash -c 'cd ...
2
votes
0answers
52 views

Read output in `screen` from outside

Suppose I opened up a screen to run some program that outouts some result. Once the program finishes, is there a way to get the result in the screen from outside. For example: I opened up a screen ...
146
votes
2answers
29k views

Difference between nohup, disown and &

What is the difference between $ nohup foo and $ foo & and $ foo & $ disown
0
votes
1answer
35 views

Shell script runs differently when schedulled with cron

I have a strange problem with my backup script. To begin with, this is the backup script: ########################################################### # CODE BEGINS HERE ...
2
votes
2answers
37 views

How to specify a different “top level” name for tar?

I would like to tar root (/) and let it appear as /abc in the tar archive. Is there a tar flag for specifying a custom top-level name?
-3
votes
1answer
29 views

How can I apply floating point discounts and taxes in a shell script?

I want to input a number and then add taxes and subtract discounts. I am trying: #!/bin/sh printf "Please enter purchase amount: " read purchase_amount if test $purchase_amount -lt 1000 then ...
0
votes
0answers
31 views

Extracting trace information using gawk

I am new to awk programming and am using gawk to extract trace information from a mrt file in order to use it further for analysis. I have successfully been able to extract trace information from a ...
2
votes
3answers
62 views

Bash: issuing trap twice

I have a very simple question. I can't believe the Bash manpage doesn't explain this already, but anyway... If I issue the trap builtin twice [for the same signal], what happens? Is the second ...
0
votes
2answers
46 views

Why doesn't this pipe command work at this special bash script?

That script test.sh doesn't work after used pipe command. The result shows nothing. Why? #!/bin/bash fun=$( echo $1 ) echo "$fun" commands are as follows, $ echo 1 | ./test.sh
25
votes
3answers
11k views

How can I make iconv replace the input file with the converted output?

I have a bash script which enumerates through every *.php file in a directory and applies iconv to it. This gets output in STDOUT. Since adding the -o parameter ( in my experience ) actually writes ...
4
votes
2answers
452 views

What are the shell's control and redirection operators?

I often see tutorials online that connect various commands with different symbols. For example: command1 | command2 command1 & command2 command1 || command2 command1 && command2 ...
1
vote
2answers
465 views

I want to suppress “no access to tty” error message?

I have a bash script where I use ssh to connect to another server and run some commands there. I found some sites that the error (Warning: no access to tty (Bad file descriptor). Thus no job control ...
1
vote
1answer
44 views

How do I add something to the end of “}” if a pattern is matched?

If I have something that looks like this: hello {sdsdsdsds} pattern {askjdasjkdjasd} hello {siadsd} pattern {iuewer} So if pattern if matched before {*}, I need to add a ;. Output: hello ...
7
votes
4answers
493 views

List the number of lines in files

How can I list the number of lines in the files in /group/book/four/word, sorted by the number of lines they contain? "ls -l" command lists them down but does not sort them
1
vote
1answer
30 views

login/non-login and interactive/non-interactive shells [duplicate]

Are the concepts of login/non-login shells the same as the concepts of non-interactive/interactive shells (respectively)? Or are the concepts orthogonal yielding four different combinations? I am ...
6
votes
4answers
302 views

what's the difference between using 'single quotes' or not in find command

find ~/ -name *test.txt find ~/ -name '*test.txt' Can anyone help me to construct an example where the first form fails but the second still works. And tell me the difference between them.Thanks!
2
votes
2answers
63 views

How to search empty alternation with tcsh

I want to search some empty alternation with ls but nothing is working. I have a list of files: foo.txt foouubar.txt fooubbar.txt fooubar_1.txt foounix.txt I want to have only foo.txt and ...
2
votes
1answer
47 views

Execute command that was displayed on the screen as a message

A message is displayed many times on the screen after entering certain command. I need to retype the entire suggested command or copy and paste it. Is there a shortcut to do the same using the ...
113
votes
15answers
58k views

How to do integer & float calculations, in bash or other languages/frameworks?

Using echo "20+5" literally produces the text "20+5" What command can I use to get the numeric sum, e.g. 25 in this case. Also, what's the easiest way to do it just using bash for floating point, ...
3
votes
1answer
39 views

Problem with getting interactive input in while read loop

I was doing something like the following minimal example: #! /bin/sh # $1 = file containing list of files to sync # $2 = source dir ; $3 = target dir cat "$1" | while read f do cp -i "$2"/"$f" ...
1
vote
2answers
131 views

Can I hook into the cd command?

I'm trying to set something up on a server I run, when ever I cd into a public_html folder 95% of the time there's a few commands I will always run to check certain things. Is there anyway I can hook ...
2
votes
2answers
248 views

How to create an alias for a sequence of commands? [duplicate]

I know it for one command but how to work with a sequence?
1
vote
2answers
45 views

how to extract path from file location using shell [duplicate]

how to extract path location from below given string. /opt/oracle/app/oracle/product/12.1.0/bin/tnslsnr expected output. /opt/oracle/app/oracle/product/12.1.0/bin (or) ...
27
votes
2answers
2k views

How does `cat <> file` work?

cat < file prints the contents of file to stdout. cat > file reads stdin until Ctrl+D is detected and the input text is written to file. cat <> file, at least in my version of Bash, ...
2
votes
2answers
81 views

Update process name in shell, is it possible?

In C/C++ it is in general possible to do strcpy(argv[0], "new process name"). It's a hack used in malicous software to hide real process name. Is such operation possible via shell? What I want to do ...
1
vote
5answers
98 views

find the max value of column 1 and print respective record from column 2 from file

How to find the max value from the column 1 and echo the respective path location from a file which contains n number of records. $ cat version.log 112030 /opt/oracle/app/oracle/product/11.2.0 ...
1
vote
1answer
83 views

How to keep running a process in Android when disconnecting adb terminal? command “nohup” not found

I'm trying to analyze the reason for random reboots of my phone (see here). Therefore I wanted to record the logcat and kernel messages till the restart to see the logs even after the usb disconnects, ...
4
votes
3answers
6k views

bash: /home/user/.ssh/authorized_keys: No such file or directory

Create a ssh key: $ ssh-keygen -t rsa –P "" Moving the key to authorized key: $ cat $HOME/.ssh/id_rsa.pub >> $HOME/.ssh/authorized_keys bash: /home/user/.ssh/authorized_keys: No such file ...
79
votes
8answers
92k views

Colorizing your terminal and shell environment?

I spend most of my time working in Unix environments and using terminal emulators. I try to use color on the command-lin, because color makes the output more useful and intuitive. What are some good ...
2
votes
3answers
45 views

How to parse env variable in a quoted string?

I'm having a hard time getting the value of an environment variable ($GHREPO) in a quoted string. Here is the command I'm running. I'm trying to make a directory with the value of ...
2
votes
1answer
65 views

find and sed (find and replace) causes illegal byte sequence on Mac OS X

I am attempting to perform a find and replace of underscores to dots in a directory for certain filetypes only (.mkv, .mp4, .avi). This is the code that I am using (I'm on Mac OS X 10.9): find . \( ...
2
votes
2answers
987 views

Using sudoers to allow php to run command

I am trying to get my php page to run this command: shell_exec("sudo /home/xbian/433Utils/RPi_utils/codesend {$num}"); So I added this entry to my sudoers file with visudo: www-data ALL=NOPASSWD: ...
84
votes
3answers
5k views

Why not use “which”? What to use then?

When looking for the path to an executable or checking what would happen would you enter a command name in a Unix shell, there's a plethora of different utilities (which, type, command, whence, where, ...
4
votes
2answers
90 views

Using `case` to handle script arguments

Can I use the case statement to handle arguments? So, using -restart I'd like execute "-umount" and "-mount" #!/bin/bash case "$1" in -mount mount /ip/share1 /local/share1 ;; -umount umount ...
6
votes
7answers
493 views

Command line tool to “cat” pairwise expansion of all rows in a file

Suppose I have a file (call it sample.txt) that looks like this: Row1,10 Row2,20 Row3,30 Row4,40 I want to be able to work on a stream from this file that is essentially the pairwise combination of ...
23
votes
4answers
2k views

Is there a simple Bash tool which can quickly render basic HTML?

From time to time I need to do a simple task where I output basic HTML into the console. I'd like to have it minimally rendered, to make it easier to read at a glance. Is there a utility which can ...
1
vote
2answers
66 views

Compare and print data from different text files to one in Shell

How can I compare and print data from different text files to one in Shell. I have captures NAS details of three different boxes using SSH, now I need to combine all the three text files to one file ...
1
vote
1answer
60 views

How do I put a time stamp with: wget --output-file=[FILENAME] [URL]

So I've been trying to put a timestamp on some images I'm downloading from a webcam, but so far it's been saving the images with the names camera3_date' here's my line that I enter: wget ...
0
votes
1answer
46 views

check status process output

I wanted to understand how to create a script sh that allows me to see if an additional script functions correctly. For now this is the script that I created. if /run.sh status echo "$SERVICEXE ...
2
votes
3answers
2k views

cshrc execute bashrc within itself?

My school has our Linux accounts using csh/tcsh by default. I, however, have a lot setup on my home bashrc and I'd like to use that at school. BUT there's also some important stuff that happens in our ...
0
votes
1answer
32 views

Trying to debug /etc/init.d/named, no output, replace > /dev/null with /var/log/named.log?

I'm trying to debug named, when I try: [root@test master]# service named start Starting named: [FAILED] it fails silently, so I tried: sed -i ...
15
votes
3answers
6k views

Bash: double equals vs -eq

I am doing integer comparison in bash (trying to see if the user is running as root), and I found two different ways of doing it: Double equals: if [ $UID == 0 ] then fi -eq if [ $UID -eq 0 ] ...
2
votes
2answers
100 views

How to read from a named pipe after the writer process exits?

I want to use named pipes as asynchrnonous task queues (JMS-like, perhaps). For example, suppose a client sends some data that I wish to insert into a database, but I want the client to disconnect ...
3
votes
2answers
2k views

Close all file descriptors in bash

Is there a way to close all the open file descriptors, without having an explicit list of them beforehand?
3
votes
4answers
303 views

How to use sed to selectively remove leading zeros

How can I substitute/remove 0's in this, using sed: 2001:0db8:03cd:0000:0000:ef45:0006:0123 to make it looks like this: 2001:db8:3cd:::ef45:6:123 There are 8 pieces of 4's divided by : in the ...
1
vote
3answers
3k views

Removing a directory from PATH

I'm trying to compile wxWidgets using MingW, and I have cygwin in my path, which seems to conflict. So I would like to remove /d/Programme/cygwin/bin from the PATH variable and I wonder if there is ...
11
votes
2answers
11k views

How to print only the duplicate values from a text file?

Suppose there is a column of numeric values like following: File1: 1 2 3 3 3 4 4 4 5 6 I want the output: 3 4 That is, only the repeated lines. Is there any command line tools to find this ...
2
votes
3answers
70 views

Using a command's output to determine the name of the file to redirect output to

I want to run smartctl -a, and use the device serial number from that output as the name of the file to store the output in. I know this can be done by invoking smartctl twice, and slicing up the ...
3
votes
2answers
122 views

single quote within double quotes and the bash reference manual

In section 3.1.2.3 titled Double Quotes, the bash manual says: Enclosing characters in double quotes (‘"’) preserves the literal value of all characters within the quotes, with the exception ...
13
votes
2answers
836 views

How can variables use “~” for cd'ing?

How can I use a variable - $BASE in my cd. I tried the following but I get an error $ cd ~/z/repo_1_ruby_193/ 23:23:57 durrantm Castle2012 /home/durrantm/z/repo_1_ruby_193 $ BASE="~/z" 23:24:03 ...