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)

1
vote
3answers
113 views

How to print new lines at the end of functions?

If I type echo hello, my terminal looks like this: My-Computer:~ user$ echo hello hello My-Computer:~ user$ But if I have a function like this stringen () { cat /dev/urandom | env LC_CTYPE=C tr ...
1
vote
0answers
12 views

How Can I be Assured That my Issue Can be Helped Here?? [migrated]

As a relatively new StackExchange User and Contributer, I see a lot of the same questions in some form or fashion day after day. I don't mind helping each visitor, but before I do, I always have a ...
2
votes
3answers
41 views

SSH command with file redirect not working

I want the following command's result to redirect into a file on the remote server, as I want only unique lines in my authorized_keys file: ssh root@10.100.10.26 awk '!seen[$0]++' ...
11
votes
4answers
1k views

Shell: “Display all 2588 possibilities?”

So, I was moving my laptop around (and I have the bad habit of setting things on the keyboard...) and I woke up to discover this: $ Display all 2588 possibilities? (y or n) What command would ...
1
vote
1answer
32 views

bind -x leaves terminal in a state resembling ^V

I define a shell keybinding in my ~/.bashrc like so: bind -x '"\e\C-w":"/usr/bin/reset"' This does make Ctrl-Alt-w launch the reset executable. However, it leaves the terminal in a state that ...
34
votes
1answer
748 views

Security implications of forgetting to quote a variable in bash/POSIX shells

If you've been following unix.stackexchange.com for a while, you should hopefully know by now that leaving a variable unquoted in list context (as in echo $var) in Bourne/POSIX shells (zsh being the ...
0
votes
2answers
38 views

append time to log filenames

I want to make log_files named as log_Jan_01_hh:mm:ss, so the variable time-stamp is defined as date +"%b_%d_%T". Now if I set the value to a variable: setenv now `date +"%b_%d_%T"` Then $now ...
2
votes
1answer
38 views

Find Command: File Path vs -name Argument

I'm currently building a script to handle some files in a directory. In the first example, I use the find command and pass a directory in as the argument. In the second I instead use the -name switch ...
0
votes
4answers
55 views

Print last character in the given path

I am trying to concat "comnp.dat_CY*" files into one file. File name, source path and destination path are the parameters. I am trying to find the last character in the path to check if it is "/" or ...
2
votes
2answers
42 views

find and delete gives false status

I tried to execute delete as per many previous discussions occurred find & delete however my attempts lead to different experience. find . -type d -name "koko" -exec rm -rf {} \; deletes the ...
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 ...
0
votes
1answer
37 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
49 views

Event not found in sed call in csh script

I tried the code as given on delete text between curly brackets however I am facing this different error regarding event in sed. file contains: This is { {the multiline text} file } that wants { ...
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
1answer
122 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 ...
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 ...
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 ...
1
vote
1answer
32 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 ...
2
votes
4answers
77 views

How do I use newlines inside () with sed?

When I want to replace, say Dot with Dot ##empty line## I do this: sed 's/Dot/Dot\ /g' Yes, a literal new line, this is the way it works on BSD sed. But, I can't do the same when the sed is ...
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
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 ...
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 ...
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
3
votes
1answer
40 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 ...
7
votes
4answers
498 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
2
votes
2answers
249 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
46 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) ...
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 ...
6
votes
4answers
303 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
3answers
50 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
2answers
83 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 ...
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 . \( ...
4
votes
2answers
91 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 ...
1
vote
1answer
63 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
47 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 ...
1
vote
2answers
67 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 ...
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 ...
32
votes
3answers
2k views

Why is using a shell loop to process text considered bad practice?

Is using a while loop to process text generally considered bad practice in POSIX shells? As Stéphane Chazelas pointed out, some of the reasons for not using shell loop are conceptual, reliability, ...
1
vote
1answer
87 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, ...
6
votes
7answers
495 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 ...
3
votes
4answers
306 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 ...
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
837 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 ...
2
votes
2answers
114 views

How can I test for a file having a value?

I am using source ~/.rvm/scripts/rvm repos="repo_1_ruby_193 repo_2_ruby_211 repo_3_ruby_191" > rvm_check.txt for repo in $repos do cd ~/zipcar/$repo 2>rvm_check.txt cd .. echo $repo if ...
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 ...
1
vote
2answers
209 views

how to shutdown another computers by using their IPs in shell script [closed]

command to shutdown to collection of servers by IP in specific time by shell script "using ssh command"
1
vote
1answer
43 views

How do you make case statements with ranges

I'm supposed to: Make a case statement that will display the a grade after input. With no loop or conditional. A=90-100, B=80-89, C=70-79, D=60-69, F=0-59 This is what I have so far: ...
2
votes
3answers
177 views

How to create multiple files with different names and different extensions?

I'm trying to create some files that has different names and with different extensions. Let say I want to create for example 3 files with following name and extension: File001.000 File002.001 ...