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

What is the difference between the built in echo command and /bin/echo? [duplicate]

I was playing around with the type and which commands and I discovered something strange. type either returns the path or says that a command is a Bash built in. which either returns the path or ...
0
votes
0answers
39 views

How to decrease the RAM and Cores for sometime

I have 9 VMs running Ubuntu 12.04.I am using resources from GENI ( Global engineering Network Infrastructure ) to set up topology and i reserved resources with the following configuration. RAM - 4GB ...
3
votes
1answer
31 views

Terminating SSH called from a script (SIGPIPE handling?)

so I was wondering why there are some hanging SSH connection left from some of my automated scripts and I came to a weird issue - SSH, if used without PTY, doesn't terminate when the output pipe gets ...
1
vote
2answers
59 views

How to do a grep on remote machine and print out the line which contains those words?

I have few logs files in my machineB under this directory /opt/ptd/Logs/ as shown below - My logs files are pretty big. david@machineB:/opt/ptd/Logs$ ls -lt -rw-r--r-- 1 david david 49651720 Oct 11 ...
5
votes
1answer
36 views

Representing/quoting NUL on the command line

Can \0 be used on the command line? Background For testing corner cases in GNU Parallel I was curious whether all characters were correctly quoted on the command line. Most of them are: perl -e ...
6
votes
5answers
255 views

Number of characters in a shell command's output

I am writing a script which needs to calculate the number of characters in a command's output in a single step. For example, using the command readlink -f /etc/fstab should return 10 because the ...
4
votes
1answer
82 views

How can I create an alias that passes additional arguments?

I have an executable that I use often: /dir1/dir2/dir3/dir4/executable argv[1] argv[2] argv[3] I know that I can set an alias for the executable: alias myexecutable = ...
0
votes
3answers
27 views

Redirect stderr and stdout to another file descriptor

exec 6>&1 will copy file descriptor 1 onto 6. But how can I copy both stderr and stdout (1 and 2)to file descriptor 6 ?
1
vote
1answer
23 views

Define custom login shell in schroot

According to the schroot man page: schroot allows the user to run a command or a login shell in a chroot environment. If no command is specified, a login shell will be started in the user's ...
3
votes
3answers
127 views

Can you source a “here document”?

Let's say I have a bash script that acts as a config file for another bash script: config.sh: verbose=yes echo "Malicious code!" name=test script.sh: source config.sh echo "After sourcing: ...
2
votes
0answers
39 views

bash syntax error near unexpected token `(' - but everything looks like it should work [duplicate]

I'm trying to write a bash script which will copy a bunch of files and directories from a directory, omitting a couple but taking everything else. I have got a command that does this and works from ...
1
vote
1answer
69 views

One-Click Script to Gmail Yourself a File

Does such a thing exist? I'd be interested in something like: You right-click a file in a file viewing manager, and click "gmail yourself this file". One click, and you're done. You open up the ...
0
votes
1answer
33 views

Shell script permission denied despite +x flag

This is an odd one, it only happens on one server (shared hosting, so I have limited access to configuration and logs), but I can't wrap my head around it. I have a shell script which runs some app's ...
4
votes
2answers
321 views

How to check whether a process is daemon or not?

I have written a small daemon that starts at the boot time and does all the things perfectly like writing in the log file. But I want to know, how can we check whether that process is daemon or not? ...
1
vote
2answers
87 views

bash question about if and then [duplicate]

I'm writing this in my script. It has other parts but I'm getting stuck on this part only. if [[$# == $year $month $day ]] ; then cal $day $month $year fi When I run this it give me this msg: ...
-1
votes
1answer
62 views

just wanted to know what am i doing wrong in the end of this script that doesnt put my checkdate in to cal command

#Purpose: Validate a date #Usage: chkdate year month day # if [ $# -eq 0 ]; then echo Usage: chkdate year month day exit 0 fi year=$1; month=$2; day=$3; extra=$4 if [[ "$extra" != "" ...
0
votes
1answer
39 views

nmap won't recognize a hostname on my local area network

Scanning the machine on the LAN with my laptop, I got this: gabriele @ osiris { ~ } [ Tue Oct 07 ] [ 08:49 PM] nmap -sP 192.168.1.236 Starting Nmap 6.40 ( http://nmap.org ) at 2014-10-07 20:50 CEST ...
2
votes
4answers
194 views

Creating symbolic link recursively

I essentially want to run this command... ln -s /opt/gitlab/embedded/service/gitlab-shell/hooks/ /var/opt/gitlab/git-data/repositories/web/*/hooks This would create a symbolic link in all folders ...
2
votes
3answers
63 views

How to nest quotes in bash commands

I want to test the result of this command: dmesg | grep "Firmware patch 1563" Therefore, I try to write something like this: if [ "`dmesg | grep "Firmware patch 1563`" == "" ] But it doesn't ...
0
votes
1answer
36 views

Options to a command specified in a file

How can I have some of the options to a unix command come from a file? That is the file does not contain all the options -- other options are specified elsewhere. For example I have the ...
2
votes
1answer
63 views

bc behaves differently on Solaris and Linux

I have the following problem that I have not resolved for a long time now. We have a Linux (x86_64 GNU/Linux) server and a Solaris (SunOS 5.10 i86pc Solaris) server where I work. On the linux server, ...
4
votes
2answers
173 views

How to escape single quotes correctly creating an alias

I've been given this one-liner to know how much memory my processes consume. $ ps -u $USER -o pid,rss,command | \ awk '{print $0}{sum+=$2} END {print "Total", sum/1024, "MB"}' Now I'd like to ...
4
votes
2answers
303 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 ...
9
votes
5answers
1k views

Is there a difference between `;` and `&&` and `|`? [duplicate]

When you want to run multiple commands you can use ;, && and | Like this: killall Finder; killall SystemUIServer, cd ~/Desktop/ && rm Caches Or: man grep | man cat for example. But, ...
4
votes
2answers
52 views

How to exchange words in a filename using the shell?

One of my customers is a school. On their file server all projects have a directory with the same naming scheme. <last name>, <first name> <second name>? - <project ...
2
votes
2answers
48 views

Is there an improved version of “pick” that will work with filenames with spaces?

Is there a version of the pick script that will work properly with spaces in the filenames? This is a tricky question—pick is trivial to enhance to work with spaces in filenames, but the output ...
0
votes
1answer
48 views

move files of a particular pattern to another directory

In the directory /home/in I have files like this: crust.MC12345.txt crust.etcMC12345.txt crust.MC23456.txt crust.etcMC23456.txt crust.etctcMC23456.txt I only need to move crust.etcMC12345.txt ...
0
votes
0answers
44 views

Making A Shell Script To Write To XML File

I am writing a shell script to make writing my RSS a whole lot easier. Right now I am stuck at how to properly edit my files. See, I want the program to take in data from me, and then save those to ...
1
vote
1answer
29 views

Using bash environment from an external OS partition

I have an external partition, /dev/sda, which contains an Ubuntu OS. The root is located in /dev/sda2. I would like to access commands from this OS partition. I have tried doing the following ...
2
votes
3answers
65 views

Redirect stderr to a file, but create only if any stderr happened? [duplicate]

I'm running a command like: parallel --spreadstdin --line-buffered 'some_command 2> `mktemp --tmpdir /tmp/stderr`' | do_something The trick is that parallel creates a lot of processes and they ...
1
vote
2answers
28 views

Listing folder contents during cd command

I might be mistaken here, but I was watching someone navigate using the cd command, and without actually executing it, they were able to show the folder contents of the current folder. So if I type ...
16
votes
5answers
2k views

Why do I sometimes get repeatedly prompted with “>” in the terminal?

Alright, when I run certain commands the wrong way, (misspelled, etc.) The terminal outputs this: > instead of computername:workingfolder username$, and when I type enter it goes like this: > ...
0
votes
2answers
50 views

copy and rename script

Directory A: 1111111_1.pdf 2222222_1.pdf 1234567_1.pdf Directory B: abcdefg.pdf zzzzzzz.pdf 1234567.pdf 1111111.pdf 2222222.pdf ...
33
votes
2answers
2k views

How do I open an incognito bash session?

Is it possible to open an incognito session in bash? For example, when we need to enter passwords in commands and don't want bash to add them to history.
0
votes
1answer
51 views

How to wait until script ends - csh?

I execute a script that splits a big file into little files. Immediately afterwards I ask if (-f *filename) then .... Sometimes the script doesn't finish so the if doesn't work. I tried sleep but ...
9
votes
4answers
243 views

Unexpected EOF and syntax error

I am currently writing my third ever shell script and I have run into a problem. This is my script so far: #!/bin/bash echo "choose one of the following options : \ 1) display all current users \ ...
1
vote
3answers
59 views

I want to divide a sum of numbers by a value

So here is my code for Unix shell scripting #! /bin/ksh echo "Enter your first number:" read first echo "Enter your second number:" read second echo "Enter your third number:" read ...
2
votes
3answers
102 views

Call sed to replace a string stored in a bash variable

I want to expand a variable in bash with sed or awk. This variable is an array. For example, the script must delete strings contained in array. I tried ARRAY1=( string1 string2 string3 ) sed -i ...
4
votes
3answers
155 views

Script to compare 2 input paramters and show shared letter(s)

I am writing a script that I want a user to enter two separate words, and the result to show which letter the two words share. For instance ./share Cat Rat - would return shared letters: "a" and "t". ...
2
votes
1answer
92 views

Writing to an interactive prompt

I’m using the ftp command line tool and want combine scripted input with user input. With only user input the prompt looks like this: ftp> But when I try to insert some input with a script, like ...
4
votes
1answer
63 views

Length of argument inside a function of an sh script

I have a FreeBSD 9.3 RELEASE server and I am trying to write a shell script using sh. I am trying to get the length of a variable that is passed to a function in a shell script, like so: #!/bin/sh ...
2
votes
1answer
77 views

auto complete in shell script

My folders are named by date: 20140930DoingShellStuff 20140931HopefullyShellIsDone ... What I want to do is write a shell script to auto cd into the folder which corresponds to the current date. I ...
-2
votes
1answer
90 views

Delete all mails from inbox using linux command prompt

How can I delete emails from an individual email account? e.g. how can I empty userxyz@mydomain.com? I know the following: /var/spool/mail/mydomain /var/mail/mydomain I have many inboxes some of ...
0
votes
1answer
28 views

Replace copyrights recursively [duplicate]

I have many files under the current directory. Each file contains copyrights headers like, # # Copyright 2013 Company, Inc. All rights reserved. This software # is property of Company, ...
3
votes
4answers
313 views

How to return a background task to be in the foreground?

Well, the title does not say much, but I would like to know how to stop a running process after appending it with &. For example, I would like to install software foo. Now, assume, foo has many ...
0
votes
1answer
58 views

Unix: What happens if I enter ls -d [2-q]*

Would it just ignore the bit after the -d option since you cant arrange characters lexically between 2 and q?
1
vote
0answers
21 views

Can I use modulecmd with fish shell?

At work we use the Environment Modules package (and hence modulecmd) extensively. man module includes the sentence “The sh, csh, tcsh, bash, ksh, and zsh shells are supported by modulecmd.” This is ...
6
votes
1answer
127 views

cd and ls behave differently when inside a softlink to a dir

When we cd into a dir via its softlink, i observe: ls .. will show the content of the parent dir of the linked dir, while cd .. will go under the parent dir of the softlink. Why are they different? ...
1
vote
1answer
37 views

Run Comand on all files (folders ad subfolders) [duplicate]

All, I have a lot of PDF files. Does there exist a way to apply to all PDFs in folder and sub-folders at one time? Example, I have: /pdf/test/pdfa.pdf /pdf/example/aa/test.pdf I'd like to apply ...
4
votes
1answer
79 views

Problem combining -or and -exec with find command

I'm finding that when I use find's -or operator in combination with -exec, I don't get the result I expect. When searching for .cpp and .h files, the command works as expected if I don't use -exec: ...