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
2answers
21 views

Copy plaintext lines from file and append them to same file with mid-line prefix or remove mid-line prefix

Making an ugly script that compiles a bunch of hosts files into one big list. Most lists will have two entries for a URL, one with www. and one without like this: 127.0.0.1 facebook.com 127.0.0.1 ...
5
votes
1answer
47 views

Ctrl+c and Ctrl+z to interrupt/suspend jobs

To kill a hanging job, I use Ctrl+c, to send an interrupt signal to the hanging job. Sometimes this wouldn't stop the job, at least not immediately. I can then use Ctrl+z to suspend the job and then ...
1
vote
5answers
263 views

To remove extra space from line using shell command

This is my file, TLRUIDA CBdms Status DP 6/1/1 DC 6/1/5 0 Y TLRUIDA CBdms Status DP 6/2/1 DC 6/2/5 0 Y TLRUIDA CBdms Status ...
-1
votes
2answers
37 views

ssh linux to mac inside and outside lan

Hi this is my first post and I was wondering if anyone can help me? I have ubuntu on my home pc and I want to be able to ssh to a macbook. When they are both on the same wifi network it's no problem, ...
1
vote
0answers
52 views

File exists but errors with “mv: cannot stat: No such file or directory”

For some reason my script cannot copy or move files that exist. It comes up with the errors below. Can someone tell me why? cp: cannot stat '/mnt/sd/bbu/install/scratch/bin/.': No such file or ...
2
votes
3answers
101 views

How to make xargs handle spaces and special chars from cat?

I have a file that contains a list of names. i.e.: Long Name One (001) Long Name Two (201) Long Name Three (123) ... with spaces and some special characters. I wanted to make directories out of ...
0
votes
1answer
24 views

Conditionals do not work in . ./script [closed]

I am trying to make a history file manipulations scripts. When I try to, for instance implement an incognito mode by running unset HISTFILE It doesn't work due to command running in new shell. ...
1
vote
2answers
28 views

Inline sound effect using command line

I found a while ago a way to modify recorded sound (pitch and such) and playing it through speaker in a single command line, involving "rec", piped to another command... But silly me, I didn't save it ...
1
vote
2answers
51 views

Backtick command encapsulation

test@debian:~$ echo `echo \`echo "uh!"\`` uh! How does the Bash do that? It seems that it first executes the expression in the non-escaped backticks, which gives back (the double-quotes "" are ...
0
votes
1answer
33 views

colored bash does not work as root user

I have noticed that when I ssh to a server and then su to the root user, I do not get color in bash. In this specific case when I say "do not get color in bash" I am talking about editing files with ...
10
votes
2answers
1k views

Is the “$?” (dollar-question mark) variable available only in the Bash shell?

In the Bash shell, I can get the command exit status through the $? variable: # ps -ef | grep "haha" root 15439 15345 0 23:02 pts/0 00:00:00 grep --color=auto haha # echo $? 0 Is it ...
3
votes
2answers
33 views

Why builtin times doesn't work in pipeline?

I've the following sample script: #!/usr/bin/env bash sleep 5 printf "times cmd: " times printf "pipeline: " times | ( read user sys; echo $user; ) printf "head: " times | head -n1 printf "times cmd ...
-1
votes
1answer
17 views

Lock a Application Through Terminal

I was wondering if it were possible to lock a Application through Mac Terminal. I know there's a way to lock files, using chmod a+x 000 'directory', but it never worked with an Application. What I ...
3
votes
2answers
43 views

Parameter expansion on multiple variables

Parameter expansion on a single variable works as expected. But how to expand parameters that comprise several variables? Example: #!/bin/sh foo=/lorem/ipsum; bar=dolor/sit tmp="$foo/$bar" printf ...
2
votes
4answers
95 views

Moving and renaming hundreds of .jpg files, all named 5003.jpg

So here's the deal, my girlfriend wants me to transfer all of her photos off from her iPhone onto her laptop (on which we are running Ubuntu 14.04). All of the dedicated programs I tried to do this ...
1
vote
2answers
37 views

What is the difference between . and the current directory?

I'm trying to copy the current directory as a source. Using full paths gives me the expected behaviour, copying the entire directory into the destination. $ cd /tmp $ mkdir a b $ cd a $ touch 1 2 3 $ ...
1
vote
2answers
88 views

Full file date (without GNU utilities)

I am trying to obtain the full date (created or modified) of a particular file for passing to another program. I have tried variations of options with the ls command but none provide a full date for ...
1
vote
1answer
59 views

how concatenate two commands?

Please can someone help me to concatenate two commands on shell, I'd have the path result and concatenate with the number of column in the first field. EX: #this gives me the path of my path ...
0
votes
2answers
22 views

Running shell job on remote server, closing terminal without closing job

I am running jobs on a remote server using torque. I currently have a an annoying problem. When I run my jobs this is what I currently do: Log into another computer via Teamviewer From that ...
0
votes
2answers
73 views

Parsing HTTP response with shell

I want to parse below HTTP response but I cannot figure out how to grep the values separately using a single curl request. I need these two output. 1. status_code - (Array of HTTP status codes) 2. ...
0
votes
1answer
37 views

How to store a variable that increments by the index?

I'm very new to programming and I was wondering how I could store and print the variables that are being incremented in bash. #!/bin/bash ethcounter=$(ifconfig -a | egrep --count "eth") ...
1
vote
0answers
15 views

Schedule (Cron) executing tasks based on bash scripts using CronniX

I'm still quite new you Mac and OS X but do have some background about other UNIX based systems, so please excuse for any misunderstandings. My goal is to implement a function that executes certain ...
1
vote
1answer
23 views

How to Load data to one table from Multiple excel files?

I have to load data from multiple excel file into one table , Please help me to achieve the solution. We are getting excel file from different retail shop which contain multiple column , each file is ...
1
vote
0answers
23 views

Start a subshell then run commands

Say I have a script that is always run from an interactive shell. I would like this script to launch an interactive subshell that is a replica of the parent (i.e., all environment variables, etc. ...
0
votes
0answers
28 views

ssh some commands through (a variable amount of) intermediary hops

(I hope I did search the se sites correctly to avoid duplicates: I did not find a similar question/need, and most similar questions only hop through 1 hop) : the need: I need ideas to create a way to ...
0
votes
1answer
16 views

Getting error while using httpd -v command in script

I wrote a script to check the details of Web server's(RHEL) and save the output into a file. But the script is not passing the command httpd -v in the loop. Here is the script. #!/bin/bash for i in ...
1
vote
2answers
17 views

Find unique lines based on only a section

I am wondering if there is a way to split lines by some character (E.g. :) and find unique lines based on one part of this split. For example if I had the following piped in via stdin file1: line 4 ...
3
votes
0answers
58 views

Shell Arithmetic Expansion with Quotes

In Bash and Dash, using quotes in an Arithmetic Expansion is illegal: $ bash -c 'x=123;echo $(("$x"))' bash: "123": syntax error: operand expected (error token is ""123"") $ dash -c 'x=123;echo ...
3
votes
3answers
155 views

Recursive Function not Working

I know that this is a ridiculous idea, but I'm trying to get a script to work that branches through every directory on the file system. The file's name is "Everywhere.sh". Here's the code: ...
0
votes
1answer
39 views

How to replace single quotes and &apos in a file

I am trying to replace single quotes in a file and I used the command as sed /s/'//g filename and this command works fine but I have &apos character also in my file and which is not getting ...
0
votes
0answers
10 views

adding and removing printers in MAC OS X Yosemite

I work in a school district and using DepoyStudio to remove and add printers on OS X Yosemite. I've tested both shell scripts in terminal and they work and when I use deploystudio workflow it runs ...
1
vote
2answers
61 views

Linux shell that allows you to choose from tab completion

This is an odd question, and I don't have a lot of information to provide but .. I recall seeing a Linux terminal that had a feature which allowed its user to choose between the options listed from a ...
3
votes
2answers
42 views

wait and recycling of PID

I have a concern whereby in a script, I will be calling parallel versions of a function to run in the background and then issuing a wait. a () { sleep $1 } a 10 & PIDs="$PIDs $!" a 50000 & ...
0
votes
2answers
130 views

How to remove a script tag from a text file with sed

I have a number of header.php files that have a malicious script tag contained within them (don't ask). I've written a not-so-elegant shell script to replace these with blank space. I had initially ...
3
votes
1answer
32 views

What is the purpose of the uucico shell on HP-UX, Solaris, and possibly other Unix varieties?

For my work, I review Unix and Linux server configurations for compliance with security guidelines. So I'm not a Unix admin myself, but I work with Unix servers on a regular basis and am fairly ...
0
votes
1answer
21 views

bash-like last command in history using up-down arrow keys in zsh [duplicate]

In bash, we can use the up and down arrow keys to get the last or nth previous command in history. Can we do this in zsh?
2
votes
2answers
55 views

Set awk array on command line?

I know the -v switch can be used to awk on the command line to set the value for a variable. Is there any way to set values for awk associative array elements on the command line? Something like: ...
7
votes
5answers
131 views

What's wrong with this for loop in bash script?

I am trying to print a simple value for $AR1_p1 but the variable $i is not evaluating. for i in 1 2 3 4 do AR1_p1=22 AR1_p2=23 AR1_p3=24 AR1_p3=25 echo $AR1_p$i done It's like concatenating ...
0
votes
1answer
23 views

regarding recursive deleting of a specific file type

I wanted to delete a specific file type say *.bak file from any directory and its subdirectories. I used the following command to find the files. find <path> -name "*.bak" -type f However, ...
0
votes
3answers
41 views

How to put variable in for loops? [duplicate]

for seq in {046725..046899} do #body done Above segment of code runs beautifully keeping preceding zeroes in seq variable but why following code segment doesn't run? Is there any way? I need seq ...
3
votes
3answers
173 views

move middle part of filename to front

I have files named in the style 02.04.11 DJ Kilbot.mp3 (for several dates) and I want to reformat the name in this manner: DJ Kilbot 2011-02-04.mp3. In other words, the current format is MM.DD.YY ...
1
vote
3answers
38 views

What does the option -9 mean for killall?

I saw the command killall -9 but there is not such a option in the man page. So now I'm a bit confused: what does -9 option mean?
0
votes
1answer
29 views

Kill process with timeout

I want to start a programm with timeout, how can I kill the process using SIGINT and SIGKILL? If the programm not terminate within 5 seconds, send SIGINT. If it’s still running after 10 seconds (in ...
-1
votes
1answer
29 views

How is a trace of commands different from shell input lines?

I am unclear about two options when invoking a bash shell process or for set: -v Print shell input lines as they are read. -x Print a trace of simple commands, for commands, case commands, ...
3
votes
3answers
42 views

How to treat numbers starting with zeroes as decimal integer

Input would be file name like following : A-B-000001-C A-B-000002-C ..... ..... A-B-999999-C All file should be sequential. I want to find missing sequential file names. For this I'm separating 6 ...
0
votes
1answer
40 views

Get the external IP address in shell without dig in 2016?

This question: "How can I get my external IP address in bash?" Solves the question with a call to dig: dig +short myip.opendns.com @resolver1.opendns.com; that is the fastest resolution possible, ...
0
votes
2answers
35 views

Use a shell variable with Awk

I have this: if [[ $1 = "-c" ]] && [[ $2 =~ ^[a-z A-Z]+$ ]] then awk -v var="$2" '{print $2}' something.txt fi What I want is with a comand like -c abc to show the lines in something.txt ...
0
votes
1answer
20 views

How to set up a pre-defined variable with multiple directory paths to use with the find command

I am looking to have a script delete files that are older than 90 days in certain directories. As in, there are 8 directories that have different paths to them. I can run the find command on one ...
0
votes
1answer
32 views

Parenthesis on echo shell command

I have this echo command: $ echo "alias notepad++="C:/Program\ Files\ "(x86)"/Notepad++/Notepad++.exe"" >> ~/.bashrc As shown in the picture it does not recognize the parenthesis.
8
votes
4answers
182 views

dirname and basename vs parameter expansion

Is there any objective reason to prefer one form to the other? Performance, reliability, portability? filename=/some/long/path/to/a_file parentdir_v1="${filename%/*}" parentdir_v2="$(dirname ...