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)

2
votes
1answer
28 views

Handling NULL characters in shell

Is there a portable way of handling NULL characters in shell? A typical example would be splitting the output of find ... -print0 with shell (and shell only) either in a pipe or in a command ...
1
vote
3answers
40 views

Replacing a “time” column with corresponding values

I have a file in the following format: "2004-04-19 12:25:57" 44 44 "2004-04-19 13:39:32" 36 36 "2004-04-19 14:00:53" 34 34 I need 2 new files: a) A file which will replace "time" values of the ...
7
votes
4answers
14k views

How to do an IF statement from the result of a executed command

I am trying to do an IF statement from the output of an executed commmand. Here is how I am trying to do it, but it doesn't work. Does anyone know the right way to do this? if [ "`netstat -lnp | ...
6
votes
3answers
147 views

Peculiar Solaris integer comparison behaviour

This one caught me unawares! We have a Solaris machine (version: SunOS 5.8) hosting a pivotal script/process which has been running for many years without complaint. We recently had cause to have a ...
0
votes
1answer
12 views

Cannot disown mplayer?

mplayer -vo null -ao alsa test.mp3 & disown It returns sh: 1 : disown: not find Why it doesn't work?
0
votes
2answers
30 views

Copy files with different names from different directories

I am trying to copy multiple files with different names from different directories, to one same new directory. The names of the directories are the same as the beginning of each filename. For example ...
11
votes
5answers
5k views

Using notify-send with cron

I am using Arch Linux with KDE/Awesome WM. I am trying to get notify-send to work with cron. I have tried setting DISPLAY/XAUTHORITY variables, and running notify-send with "sudo -u", all without ...
4
votes
1answer
659 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 ...
-5
votes
0answers
17 views

How can i write this script to fullfill my needs? [on hold]

In which I have a string ”mt school is over" If string is matches then i have to match binno-12245 If this matches then instno-4567 If this matches den i have to copy data from binno to next 11 line ...
16
votes
5answers
1k views

Why does [A-Z] match lowercase letters in bash?

In all shells I am aware of, rm [A-Z]* removes all files that start with an uppercase letter, but with bash this removes all files that start with a letter. As this problem exists on Linux and ...
3
votes
5answers
192 views

How do I *reliably* and *simply* get the current shell interpreter name?

I'm looking for a simple and reliable way to get the name of the current shell from inside a script or a sourced file (not from the command line). I would have expected to just do $(basename ...
1
vote
2answers
30 views

figure out ip addresses of all the machines remotely?

I have around 40 machines and I want to know what are their IP Address. One way is to login into those boxes and figure out their IP Address by using ifconfig command but is there any other simple way ...
2
votes
3answers
91 views

List transient files by numerical value having number greater than a given constantly varying filename

I've a directory having constantly changing filenames (by numerical value) listed as: -rw-rw----. 1 root root 10493952 May 7 10:39 A0000000.LOG -rw-rw----. 1 root root 10493952 May 7 08:38 ...
0
votes
2answers
51 views

what if I need to put a “” inside a “” in bash shell? [on hold]

I have a shell script, in which there is a command: if [ -e "./${name}/\"$1\"_page.json" ]; I noticed that unlike many other languages, the \" doesn't work. What should I do?
1
vote
3answers
70 views

Is there a way to undo a terminal command?

I just copied a whole directory into another one using cp ~/local/* ./ and actually wanted to type cp ~/local/srl* ./ so I'm founding myself with a lot of unnecessary files. I can suppress them ...
1
vote
1answer
2k views

Deleting Non-empty Directory with smbclient

How can I remove a non-empty directory with smbclient? I have tried the following: 1) rm Result: NT_STATUS_NO_SUCH_FILE listing [dir_path] 2) recurse;rm Result: No Error but also nothing ...
0
votes
1answer
21 views

Queue up multiple videos from Bash Script

-Skip to bold to skip the fluff - I'm new to ubuntu, so still learning the ropes of how bash scripting goes. I've got this code I've been working on, which works great. (side question - can I ...
0
votes
1answer
88 views

What do these commands do?

I have been working at this company for around 8 years now and something that has always puzzled me is that we have a software supplier who often connects to our network to provide user support on ...
2
votes
2answers
116 views

What's the `name` argument to `sh` for/do?

Taken from FreeBSD's man page on sh (because its the most convenient online, target platform is Debian if it matters): SH(1) FreeBSD General Commands Manual SH(1) NAME sh -- ...
-1
votes
1answer
14 views

save output into a file from sqlplus query in ksh script

The thing is that it overwrites in Result.txt and I only get the last query. How can I fix this? #!/bin/sh while read -r line do echo "'$line'" sqlplus -s whatever/whatever <<-EOF SPOOL ...
-1
votes
0answers
12 views

SFTP inside SFTP [duplicate]

I want to transfer files from serverB to ServerC while staying in serverA. Can we do sftp inside sftp in shell? If yes then how?
1
vote
2answers
88 views

How to remove a file with two words separated by a space in the shell? [duplicate]

I made a text file called hello world in my home directory. Via the shell I am trying to remove it with the rm command. However, when I execute rm hello world the shell thinks that I am trying to ...
1
vote
1answer
32 views

Provide three argument to one option using getopts in bash

I am trying to process a command line using getopts in bash. I have to pass three arguments after -w option. For example, -w 1 do loop. It should print one line before and after each line from loop ...
0
votes
1answer
14 views

How to create a module on a CentOS cluster [on hold]

I would like to create a module on a CentOS 6 cluster (e.g. module load gcc-4.7.2). Basically, I have no clue how modules work. Are there any good tutorials illustrating this or could someone ...
2
votes
1answer
28 views

What files were sourced, zsh

I use oh-my-zsh with zpretzo, and I keep forgetting the zsh files it sources that I want to edit. How can I ask the shell what source files it sourced?
1
vote
1answer
3k views

Proper escaping of double quotations for curl post data?

I'm trying to test out a server, by sending it JSON data and reading the response. I need to POST data like {"item":"value with spaces"} but when I use curl I find that it sends the backslashes as ...
0
votes
1answer
45 views

How to pass arguments to a Java process from within a shell script [closed]

This may be a duplicate but the initial questions I have found the answer did not resolve the issue. Yet another re-write of the question. I have this Java application: public static void ...
0
votes
0answers
27 views

shell script in doing operation for 2 folder tree [duplicate]

I have a directory looks like: dhcp-18-189-47-44:CE-06-new-stuctures_backup wenxuanhuang$ ls DFT-00001 DFT-00004 DFT-00007 DFT-00010 DFT-00013 DFT-00016 DFT-00019 DFT-00022 DFT-00025 DFT-00028 ...
1
vote
0answers
19 views

External monitor script has become unreliable

I have been using the following udev rule and bash script to automatically configure my external monitor for some time now, however recently the script has become unreliable, usually doing the ...
9
votes
4answers
8k views

Count number of lines of output from previous program

I'm trying to count the number of lines of output a certain program produces. The problem is, the program takes a long time to run, and I want to display the output to the user. Is there a way to ...
0
votes
1answer
21 views

How to spawn new processes for new instances of the same shell script?

I'm trying to lock a file using the command lock. It's syntax is ./lock </path/to/file/name> I need to lock a bunch of files in a given directory and in order to achieve this I'm using two ...
18
votes
6answers
68k views

How can I read line by line from a variable in bash?

I have a variable which contains multiline output of a command. What's the most effecient way to read the output line by line from the variable? For example: jobs="$(jobs)" if [ "$jobs" ]; then ...
7
votes
2answers
11k views

Running chsh does not change shell

I want to change my shell from bash to zsh. I have tried running the following while logged in as user zol: $ chsh -s /bin/zsh $ sudo chsh -s /bin/zsh zol $ su -c 'chsh -s /bin/zsh zol' # The above ...
1
vote
2answers
53 views

How to use ln -s to create a command line shortcut?

I have an sh file that I would like to be able to open from the terminal at any time. I would like to type "studio" into the terminal, and have android studio open I recall using ln -s to do this, ...
1
vote
1answer
32 views

Pass shell variables to SQL statement

I want to pass shell variables to sql statement. Both shell script and SQL statement are present in the same script file. I want the values of the variables retMonth, retLastDay and retPrvYear in the ...
14
votes
2answers
504 views

What does CTRL+4 (and CTRL+\) do in bash?

I just found out by accident that CTRL + 4 closes programs reading stdin input from the command-line. This is how it looks when I type CTRL + 4 or CTRL + / into programs reading stdin ryvnf:~$ ...
-1
votes
0answers
14 views

Debian Linux Shell has no colors and desktop files/folders gone GNOME

Hello I have installed some packages to fix sound mute, but instead, after restart I saw no icons on desktop except 'Computer'. I have opened shell and wanted to do apt-get update but saw that the ...
7
votes
4answers
2k views

How to get mount point of filesystem containing given file

I am looking for a quick way to find the mount point of the file system containing a given FILE. Is there anything simpler or more direct than my solution below? df -h FILE |tail -1 | awk -F% ...
19
votes
4answers
31k views

Testing if a variable is empty in a shell script

I have seen the following technique used many times on many different shells, to test if a variable is empty: if [ "x$1" = "x" ]; then # Variable is empty fi Are there any advantages on using ...
1
vote
2answers
64 views

Need output in a good format using shell script

I have a file, PoolReport.txt. Here is some sample data: Thu, Aug 27, 2015 7:56:29 AM PoolName,Total GB,Used GB ,Available GB ,Percent Full Oracle-RAID10,6432.539,6179.295,253.244,96.063 ...
5
votes
4answers
348 views

$@ except the 1st argument

I need to write a shell script that runs in this way: ./myscript arg1 arg2_1 arg2_2 arg2_3 ....... arg2_# there is a for loop inside script for i in $@ However, as I know, $@ includes $1 up to ...
0
votes
3answers
46 views

Rename files in directory according to name of directory

I am trying to rename a bunch of files according to the names of their directory in Linux, SSH. I have a directory called XYZ01smith. In it are four files called smith_5*.I need to add prefix XYZ01 ...
-3
votes
1answer
44 views

How can i replace a specific string within a line inside a text file [duplicate]

$ cat text.txt my name is Steven my age is 10 i like dogs What command will be fitting so that echo "Kate" will replace Steven on text.txt?
2
votes
3answers
33 views

echo and command substitution

I wrote a very basic script of command substitution which is below: #!/bin/bash files=$(ls *.fastq); echo $files The directory contains bunch of .fastq file and I just want to use echo command to ...
1
vote
1answer
28 views

Check if multiple files exist in directory

How to find multiple files present in a directory in ksh (on AIX) I am trying below one: if [ $# -lt 1 ];then echo "Please enter the path" exit fi path=$1 if [ [ ! f $path/cc*.csv ] ...
2
votes
2answers
232 views

Setting environment variables with .bash_profile: only last export works properly

I am trying to export some environment variables in Unix using .bash_profile It reads now like this: export PATH=${PATH}:/usr/local/cuda-6.0/bin/ export ...
6
votes
3answers
602 views

bash: escape individual lines from `-x` echoing

In bash, when running with the -x option, is it possible to exempt individual commands from echoing? I'm trying to make the output as neat as possible, so I am running certain parts of my script in a ...
0
votes
0answers
27 views

How do I send a variable through SSH so it can be used across servers? C Shell

EDIT: Would this be possible in bash? Note: I have to use C shell. (.csh) I have something very similar to the following code: set var = "string" ssh -X server "$var" << END * I ...
0
votes
1answer
31 views

Big XML - copy data from nth Occurrences to another file

<XML> <Employee> <firstname></firstname><lastname></lastname> </Employee> <Employee> ...
10
votes
2answers
461 views

How does a shell execute a program?

If I compile a program using gcc, and try to execute it from the bash shell, what is the exact sequence of steps followed by bash to execute it ? I know fork(), execve(), loader, dynamic linker (and ...