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
94 views

Need to capture part of file name into variable

I have bunch of CSV files named like so in a directory: s_m_u_supplemental_fields_account_9_4_2015_11_26_Error.csv s_m_u_supplemental_fields_account_9_4_2015_12_3_Error.csv ...
24
votes
1answer
700 views

Why does a unquoted wildcard work remotely with scp?

I'm typing this in Bash: scp user@remote:~/dir/*.xml . and it works, getting all the files that make the wildcard on the remote server. But why does this work? I thought that Bash expands wildcard ...
2
votes
1answer
103 views

echo the created directory name

I'm trying to echo the new directory that I'm creating in the script. BACKUP_DIR=`mkdir /tmp/"$TICKET_NUM"_EAR_BACKUP_"$(date "+%Y%m%d")"` echo $BACKUP_DIR But, the newly created directory is not ...
0
votes
1answer
104 views

What would crontab do if the server is shutdown?

Say I have a crontab like: */30 * * * * /root/scripts/remove_log_files.sh This will remove some logs that I don't want every 30 mins. What would happen if the server shutdown after 25 mins the ...
0
votes
3answers
71 views

print last line of !! command

so I want to be able to print helloworld using the !! command. I tried creating a text file with the text helloworld on it. Then I say cat textFileName It prints helloworld. Then I say !! and it ...
17
votes
5answers
2k views

Why use diff/patch when it is easier to just use cp

diff -u file1.txt file2.txt > patchfile creates a patch file which consists of instruction for patch to convert file1.txt to be exactly like file2.txt As the title says, Can't this be done using ...
1
vote
1answer
105 views

Execute two commands if the first one fails

I am writing a script.sh like: ls a || ls > /dev/null || echo "both command fails"; exit 3 echo 5 # not showed up I hope the exit 3 be only executed when both command1 and command2 failed. But ...
2
votes
1answer
231 views

How to implement dynamic bash auto completion

I have made a script that lists available projects. You can start a project by entering script start <project>. Now it would be great to enable autocompletion, so if you're entering start ...
2
votes
1answer
458 views

is it possible to check whether a local socks proxy works with shell script?

Say I have a SOCKS connection at local (established by ssh -D8888). I use this to do many things, like bypass the internet censorship. But sometimes the ssh would unexpectedly broken. Then the socks ...
1
vote
2answers
100 views

How can I disable xtrace and preserve my exit code

I'm trying to figure out a good way to disable xtrace before leaving a script. These are all being executed by Wercker, a continuous integration and deployment SaaS. A previous script of mine has run ...
6
votes
1answer
432 views

Difference between closing the terminal using the closing button, and Ctrl-D

When I'm launching a background process and then closes the terminal using the window's closing button, the background process gets killed. However if I close the terminal using Ctrl+D, the background ...
2
votes
1answer
113 views

How can script execute itself via some exec again?

I'm making script for backing up data from server, it's gonna use ssh and scp many times. My private key is password-protected, but I'm using environment without any ssh agent. I'd like to put ...
0
votes
5answers
142 views

What is the most basic version of Linux with a package-manager? [closed]

I'm starting a project where all I really want is a shell with apt-get or something similar. I've searched for small distros, and there are plenty, but I don't need any GUI other than command line. ...
2
votes
2answers
3k views

How to rename multiple files using find

I want to rename multiple files (file1 ... filen to file1_renamed ... filen_renamed) using command find command: find . -type f -name 'file*' -exec mv filename='{}' $(basename $filename)_renamed ';' ...
1
vote
2answers
471 views

How do I get / available space with “df” and output it to a log file?

With the command of df, I can get something like: Filesystem 1K-blocks Used Available Use% Mounted on /dev/root 197844228 15578648 180242500 8% / devtmpfs 4101368 0 ...
0
votes
1answer
54 views

Deleted all files in dir, except ones within a json file [duplicate]

I have a static assets server with 1 million+ images sitting in a folder, most of them I don't need anymore. I have a list of the filenames I do still need in a .json file. How in bash can I delete ...
2
votes
2answers
603 views

Is it possible to transfer a file from a Linux Bash script to Windows without mounting the server folder?

I am writing a script (Bash) to transfer files from my local Linux machine to Windows servers. The Windows servers are accessible normally using the SAMBA shares, and I am able to mount a folder to my ...
0
votes
3answers
59 views

How do I check if a given parameter is in an given array?

I have a shell script script.sh like this: names=( jack john jerry) And I want the user to type any of these three names as its first parameter, just like: ./script.sh jack If the user typed a ...
0
votes
3answers
65 views

What if I don't want to do anything in a if-then block but something in its else block?

#intro if [ -n "$1" ] then echo 666 else echo 555 fi exit; Actually I do want to echo 555 while I don't want to do anything in the first block, what should I do? I noticed ...
0
votes
2answers
77 views

how to echo $, & symbols correctly?

It'd be a very stupid question but I failed with some existed answers. what I need is very simple: out put &a on the screen while there is already a defined variable a. Here is what happened in ...
1
vote
1answer
122 views

Pass list of directories (that contain whitespaces) to a command in a script

For example, I want to execute the following within a shell script: tar cvpzf /destination/backup.tgz /directory\ one /directory\ two I wish to assign the list of paths (with whitespaces in them) ...
4
votes
3answers
178 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
4answers
167 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 ...
0
votes
1answer
35 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
164 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 ...
0
votes
1answer
98 views

Searching path as search pattern in grep command

I have saved the path in the variable . var="/home/myfolder/subfolder" Need to search whether the path in available in a text file using grep. grep -l '${var}' * >abc.txt I'm trying to list ...
1
vote
2answers
47 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 ...
28
votes
6answers
4k 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 ...
1
vote
2answers
66 views

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

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
855 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
votes
1answer
458 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 ...
0
votes
1answer
103 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 ...
3
votes
2answers
182 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 -- ...
0
votes
1answer
40 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 ...
1
vote
2answers
172 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
87 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
72 views

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

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 ...
0
votes
0answers
29 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 DFT-...
1
vote
0answers
30 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 ...
0
votes
1answer
121 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. Its 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 ...
1
vote
1answer
791 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 ...
16
votes
2answers
1k 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
vote
2answers
450 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, ...
5
votes
1answer
73 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
2answers
92 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 VM_File,...
0
votes
3answers
67 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 ...
0
votes
1answer
1k 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 main(...
-3
votes
1answer
135 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
4k 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 ...
5
votes
4answers
491 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 ...