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

Permission denied while getting the md5sum of a file using shell script?

I am running my below shell script which gets the md5sum of a files in my PRIMARY directory #!/bin/bash export PRIMARY=/data01/primary for entry in "$PRIMARY"/* do local_md5sum=/usr/bin/md5sum ...
2
votes
1answer
18 views

More shell scripts than one in one text file?

I am learning shell scripting for my introductory UNIX course at my university, and I`m curious if is it possible to have more than one shell script in one text file. What I mean by that is, for ...
0
votes
2answers
19 views

Add space after 8 characters then add space after every 4 characters

Here is the sample input: AbbigailAbieAbbyAbbi Using sed, I have separated them into 4 characters but seems like I got a problem because I have to separate the first 8 characters first then add ...
0
votes
1answer
31 views

How to invoke shell function in string? (bash)

I want to invoke shell function in string. Here is my use case: function envfoo() { env ENV_FOO=foo $@ } function envbar() { env ENV_BAR=bar $@ } $ envfoo env |egrep ENV_ ENV_FOO=foo $ ...
1
vote
1answer
2 views

Increase character width in Ubuntu server shell?

Is there any way to increase the character width from 80 to something higher in the shell in an Ubuntu server?
1
vote
2answers
136 views

I accidentally GZIPed a whole bunch of files, one by one, instead of using tar(1). How can I undo this mess?

I'm new to the gzip command, so I googled some commands to run so I can gzip an entire directory recursively. Now while it did that, it converted each of my files to the gzip format and added .gz to ...
8
votes
4answers
387 views

How do I remove spaces from shell variables?

I have done the following at command line: $ text="name with space" $ echo $text name with space I am trying to use tr -d ' ' to remove the spaces and have a result of: namewithspace I've tried ...
5
votes
3answers
113 views

I am trying to find a better/easier way to count alphabetic characters in a file or shell variable

I have a file containing the following text: we are going to write something 1 2 3 wc tells me I have 1 line 9 words and 38 characters. I'm looking to count the 26 letters only (a-z, no numbers or ...
5
votes
3answers
87 views

Bash script error with strings with paths that have spaces and wildcards

I am having trouble getting the basics of Bash scripting down. Here's what I have so far: #!/bin/bash FILES="/home/john/my directory/*.txt" for f in "${FILES}" do echo "${f}" done All I want to ...
0
votes
3answers
127 views

bash find using variable

I have an issue I don't understand. It is simple and it should work, but it doesn't. =EDITED exactly what I can see from terminal= I have a list of filenames: [molni@archlinux picasa_album]$ cat LIST ...
2
votes
1answer
35 views

how to execute a shell built-in if find found certain files

In general, if we want to execute a command if find identifies files corresponding to certain specs, we can use -exec. But in my case I want to exit the shell/script if find found a match and -exec ...
1
vote
2answers
36 views

Pass arguments to a command run by another user

I have a bash script that is supposed to take some arguments and then run in a different user: test.sh #!/bin/bash sudo su user2 <<'EOF' echo $1 EOF However it prints blank: $ ./test.sh ...
0
votes
2answers
5 views

How can I sudo su and change directory just after?

I would like to create an alias that does something like this: alias userYYY='sudo su userYYY; cd /a/path/that/only/userYYY/has/access' So then from my command line, I am logged in with a sudoer ...
0
votes
0answers
48 views

what is hexa dump and how to handle in unix? [on hold]

I am trying to extract some portion of text from the file by using awk command, The file is separated by comma. awk -F, '{print $1 FS $3 FS $6}' sample.csv But always I am getting wrong output , ...
0
votes
0answers
28 views

How to get diff for HTML reports?

echo "New defects" echo "===============================" n=0 def_num=0 while read line; do n=$((++n)) if echo $line | grep '^[[:space:]]*>' &>/dev/null; then if [ $(($n % ...
3
votes
4answers
36 views

How can I get the first match from wildcard expansion?

Shells like Bash and Zsh expand wildcard into arguments, as many arguments as match the pattern: $ echo *.txt 1.txt 2.txt 3.txt But what if I only want the first match to be returned, not all the ...
1
vote
3answers
30 views

shell script to run on boot on Mac OS X does not run all commands

On OS X, I am trying to use lingon to run a shell script upon booting. I have a file ~/desktop/_admin/boot/bootdocker.sh: #!/bin/bash boot2docker up export DOCKER_HOST=tcp://192.177.59.103:2475 My ...
4
votes
3answers
122 views

Get PID of any command in backgrounded piped sequence of commands

If, in bash, I execute: cmd1 | cmd2 | ... | cmdi | ... | cmdn & where the cmd{1..n} may not be distinct, how do I get the PID of cmdi? Alternatively, how can I signal the cmdi process? (For ...
6
votes
2answers
258 views

Compare two files and print matches

Is there anyway to get this through Unix shell scripting? I have a fileA with one column (1000 rows), and fileB with 26 columns(13000 rows). I need to search each value of fileA with fileB and return ...
7
votes
4answers
236 views

Can I specify a redirected input before a compound command?

Bash lets you specify a redirected input before a command: $ <lines sed 's/^/line: /g' line: foo line: bar Bash also lets you redirect input to a compound command like a while loop: $ while ...
7
votes
1answer
283 views

Is it possible to use `find -exec sh -c` safely?

I'm trying to use find to echo 0 into some files, but apparently this only works with sh -c: find /proc/sys/net/ipv6 -name accept_ra -exec sh -c 'echo 0 > {}' \; But using sh -c with find -exec ...
-7
votes
1answer
41 views

Questions about UNIX [closed]

Which of the following UNIX command is used to find all of the files which have been accessed within last 30 days. find . -stime -30 -exec || \; |more find . -atime -30 -exec || \; |more find . ...
2
votes
2answers
45 views

Reference a path name in `find` output results

What I would like to do is to be able to reference a find path name result as a parameter to another command without laboriously typing the full path name. Example: $ find -name testfile path1 ...
1
vote
2answers
59 views

Shell script throws a not found error when run from a sh file. But if entered manually the commands work

Im trying to use the following script to generate a sitemap for my website. When I run it as sh thsitemap.sh I get an error like this and creates an empty sitemap.xml file : thsitemap.sh: 22: ...
3
votes
1answer
61 views

How do I diff the outputs of two commands?

How can I use the diff command to compare 2 commands' outputs? Does something like this exist? diff ($cat /etc/passwd) ($cut -f2/etc/passwd)
1
vote
1answer
72 views

What is happening while executing this command cd / | vi?

When I execute the command cd / | vi, it goes to the vi editor. When I type any command it does not display the command but it gets executed and the command that is executed is not shown in the ...
1
vote
1answer
25 views

fuser output looks ambiguous

I am using fuser the output is like this: $ fuser / /: 1354rc 1362r 1370rc 1371rc 1395rc 1399rc 1403rc 1410rc 1414rc 1428r 1451rc 1458rc 1470rc 1472rc 1477rc 1480rc ...
-1
votes
0answers
11 views

/etc/logrotate.conf “/var/log/btmp” want to replace digit script [closed]

I want to replace with script.. rotate 77 "/var/log/btmp" in /etc/logrotate.conf weekly rotate 99 create dateext include /etc/logrotate.d /var/log/wtmp { monthly create 0600 root utmp ...
0
votes
0answers
50 views

What is the difference between double quotes (“”) and single quotes ('')? [duplicate]

I really do not know the usage of " and '. I want to know usage of " and '. What is the difference between echo "hi" and echo 'hi'.
-4
votes
1answer
59 views

UNIX homework question regarding piping output, I don't understand what it's asking?

Basically, I need to come up with a command that sends the contents of a file xxx into a program yyy, then the output is piped to the input of another program zzz, where the output is appended to a ...
1
vote
0answers
47 views

C Shell unfreezing using right click [closed]

I know almost nothing about Unix. I use commands like cd, rm, mkdir, cp, get, put, etc., and then simply run scripts that other people have written. I had opened C-Shell and was running a script and ...
3
votes
3answers
190 views

Method for storing/remembering one liner commands

Often when configuring and adjusting unix-based systems I use a lot of one-line commands that are difficult to remember. For example, to determine what version of ntp (the time server) is running, you ...
2
votes
2answers
44 views

Pass two (piped) shell commands as a parameter to a shell function

I have defined the following shell functions: success() { printf "[\033[32mSUCCESS\033[0m]\n" } failure() { printf "[\033[31mFAILURE\033[0m]\n" } try() { result=$($* 2>&1) if [ $? ...
3
votes
2answers
72 views

Extract csv files from path to multiple files in bash

I have a files multiple file path for backup purpose ,now i want to filter it based on ".csv " fromat. I have tried this. filesall=(/home/abc/allfiles/*) files=$((${filesall[@]}|grep -F ".csv")) ...
0
votes
1answer
41 views

Got “syntax error near unexpected end of file” in bash script

I'm making an script that gives me a day like this jjj/yyyy when I give it a day like this dd/mm/yyyy and I need it to have an error when you don't write correctly but I'm starting and it's not ...
27
votes
4answers
1k views

Does /usr/sbin/nologin as a login shell serve a security purpose?

In my /etc/passwd file, I can see that the www-data user used by Apache, as well as all sorts of system users, have either /usr/sbin/nologin or /bin/false as their login shell. For example, here is a ...
8
votes
4answers
233 views

How to assign space-containing values to variables in bash using eval

I want to dynamically assign values to variables using eval. The following dummy example works: var_name="fruit" var_value="orange" eval $(echo $var_name=$var_value) echo $fruit orange However, ...
0
votes
1answer
34 views

openSuse, not running the cron job

I have created a cron job in the /etc/cron.d/dispatchingEmail_I the permissions of dispatchingEmail_I are the following: -rw-r--r-- 1 root root 84 Sep 11 19:52 dispatchingEmail_I content of ...
3
votes
1answer
323 views

while using '$?' expression in bash script

I'm writing a simple bash script #!/bin/bash ls xyzzy.345 > /dev/null 2>&1 status =' echo $?' echo "status is $status" which finds the file xyzzy.345 and logs the result to /dev/null. ...
11
votes
2answers
184 views

Why does cat x >> x loop?

The following bash commands go into an infinte loop: $ echo hi > x $ cat x >> x I can guess that cat continues to read from x after it has started writing to stdout. What is confusing, ...
1
vote
2answers
46 views

Find doesn't want to find *.sh in certain level [duplicate]

I have a problem with find. It doesn't find *.sh files if I am in certain directory level. It does, however, find *.sql files. /path$ cd do_not_upload/updates/1.1.1/ ...
4
votes
2answers
87 views

How can I force bash to deallocate a brace expanded variable without name?

For benchmarking, I ran the command: for i in {1..100000000}; do echo "$i" line >> file done Bash expanded the braces and stored the list 1 2 3 4 5 6 ... 100000000 in memory. I thought ...
1
vote
1answer
39 views

Is autocompletion for applications done by shell?

When I type evince, and then hit tab, the bash shell will list all files that can be opened by evince, which seems to be based on the ext part of the filename. Is this done by shell or the ...
2
votes
3answers
49 views

Repeat Last N commands [duplicate]

In bash, I tried writing a script to run the last N commands. For say, N=5 for i in {1...5} do !-5 done The problem is that !-5 gets replaced by the 5th-last command on my shell (say time) and ...
10
votes
6answers
940 views

What is the reverse of echo -e?

If I have a string with nonprintable characters, new lines, or tabs, is there a way I can use echo to print this string and show codes for these characters (e.g., \n for new line, \b for backspace)?
4
votes
3answers
107 views

How do I capture stdin to a variable without stripping any trailing newlines?

In a shell script... How do I capture stdin to a variable without stripping any trailing newlines? Right now I have tried: var=`cat` var=`tee` var=$(tee) In all cases $var will not have the ...
2
votes
1answer
28 views

Can you change timestamp format for history command on tcsh

When I run history command (on tcsh), it only prints the TIME portion of the timestamp and omits the date: 3 15:07 echo $PATH 4 15:07 ls -la In bash, you can use HISTTIMEFORMAT ...
2
votes
1answer
35 views

unexpected EOF while looking for matching `"' - bash script

I just wrote a bash script (im a Newbie to shell-scripting ;) ) and always getting this EOF-Error. So here is my script (only works on OS X): #!/bin/bash #DEFINITIONS BEGIN en_sq() { echo -e ...
0
votes
1answer
44 views

$PATH environment variable does not seem to be recognized

I've made a fresh install of Debian Wheezy, and installed zsh to it. Few days after, I've done a vanilla installation of TeX Live 2014, so I added the necessary binary paths to my $PATH. Now I started ...
1
vote
2answers
49 views

Run command on startup for one user

I made a new user on my server. The user is not logged into the bash shell on startup. To do this I can run /bin/bash --login and it works. Where do I place this command so that it runs ...