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
votes
0answers
10 views

extracting non hidden files in shell scripting

In shell scripting while listing a directory need to extract non hidden files need to remove upload, archive and download example : upload archive download simple data final .bash_logout ...
-2
votes
1answer
6 views

Divide value in 1st file by value in 2nd file

I have a file with a value and a second file with the value 1024. Now I want to to divide the value in the first file with the value in the second file and store the result back into the first file. ...
1
vote
1answer
7 views

Dividing up columns and submitting the value as stdin into a seperate program within a script

I currently have two programs written in C named "remove" and "calculate". When I call ./remove it removes some data from stdin. When I call ./calculate which takes in an argument and also data from ...
0
votes
1answer
17 views

Is it possible to establish a Socket session (between Server and Client) using shell commands ?

From what I read (only the very outline, i do not know C Language) a Socket session is established between a server and a client by calling functions for both of them in a certain order. It starts ...
2
votes
0answers
12 views

List all btrfs filesystems and subvolumes in shell

Is there a convenient way to get information on all btrfs filesystems subvolumes without resorting to C, i.e. in POSIX shell ? /sys/fs/btrfs contains info only on filesystems, nothing on subvolumes, ...
4
votes
5answers
373 views

Getting the pid's of a program line by line

I can find the pid's of my program instances by issuing command like this: pidof avconv Which is giving me results 16616 16283 16279 16198 16175 16035 15073 14049 4922 But how can I output the ...
1
vote
4answers
62 views

find: missing argument to `-exec'

when I'm trying to use this command var1=`sudo -u psoadmin -H -s ssh daill_scp@files.dc1.responsys.net find . -maxdepth 1 -type f -mtime +14 -exec ls -lh \{} \; | awk '{print $5, $9}'|egrep -v ...
3
votes
2answers
39 views

GNU Parallel: Event not found (!~)

About my code: get all .txt files for each file, execute the awk command. All files are processed in parallel if colum 3 does NOT contain "needle", write line to file Result: -bash: !~: event ...
14
votes
4answers
469 views

How can I implement a circular flow of data among interconnected commands?

I know of two types how commands can be connected with each other: by using a Pipe (putting std-output into std-input of the next command). by using a Tee (splice the output into many ...
0
votes
1answer
22 views

Aliasing a command with parameter supplied to another command

Namely: I want to alias tail -f to less +F but let tail with any other parameter supplied work the same way as before.
0
votes
0answers
21 views

echo `“hello terminal” > /dev/terminal` - works for /dev/tty[2-5] but not for /dev/pts/n

I'm trying to get to know the input output systems of unix/linux systems better. Since terminals and devices are implemented to interface as ordinary files, I assumed I could on any desired terminal ...
9
votes
9answers
3k views

Is using “while true” to keep a script alive a good idea?

I'm just jumping into unix from a different world, and wanted to know if while true do /someperlscript.pl done The perl script itself internally has a folder/file watcher that executes when ...
1
vote
1answer
38 views

How to know which platform I am using in lubuntu, ubuntu or kubuntu

I need switch script in between lubuntu, ubuntu, and kubuntu. How can I know which platform the script is running in? Because uname/lsb_release never show different in those 3 releases Lubuntu$ ...
2
votes
1answer
25 views

How do I run two processes and find out when one ends in bash

I was thinking to do something like this: command1 & command2 wait Will this work? I want to proceed when command2 finishes, but command1 can still be running.
0
votes
0answers
35 views

Backup And Restore Shell Script

I have been trying to create a script that backups up a certain directory and then restores the directory. The backup works as it should but when I try run the restore function I get the following ...
1
vote
1answer
33 views

How to interactively remove all directories matching given criteria?

My script below has two problems: The script stops after first matched directory rm -i is not quite interactive What are my incorrect assumptions that make it fail? How can I fix it? ls -1A | ...
2
votes
3answers
159 views

Double square brackets for FreeBSD

I have this code: [[ "$1" =~ [/\\]$ ]] On linux it works just fine, but when I tested it on FreeBSD an error occured : ./projekt2.sh: [[: not found and it .. I there any alternative which would ...
1
vote
2answers
41 views

pipe in shell with redirection

My understanding is that a pipe in shell like a | b redirects b's stdin to a's stdout. However, I tried ls | less < somefile, the behavior is very strange. less shows the output of ls concatenated ...
-1
votes
2answers
20 views

Create new file with spaces from argument BASH [duplicate]

I need to create new file which contains spaces in it. And it is passed through the argument. This code below creates 2 sepate files. Can anyone help me how to create 1 file which will contains space? ...
16
votes
2answers
349 views

Where is “export var=value” not available?

I have picked up -- probably on Usenet in the mid-1990s (!) -- that the construct export var=value is a Bashism, and that the portable expression is var=value export var I have been advocating ...
1
vote
2answers
30 views

Porting Linux date parsing to FreeBSD

I have date in this format: date -d $datum +"%Y-%m-%d" and on Linux it worked OK but in FreeBSD says this: ERROR wrong format usage: date [-jnRu] [-d dst] [-r seconds] [-t west] [-v[+|-]val[ymwdHMS]] ...
1
vote
1answer
49 views

SHELL regular expression ends with backslash

I want to check if the pattern ends with "/" or "\" and before it can be any string. I tried this *\/ * for any string, \ for removing meaning of "/" and / for "/"
0
votes
1answer
35 views

SHELL— Date format validation

How can I check whether the format of date is correct without date command being printed? date -d $datum +"%Y-%m-%d" if [ $? -ne 0 ] ;then echo error exit fi
0
votes
2answers
46 views

What is the variable of $#?

I'm learning introductory Linux and came across something which I did not understand: "The following command has been executed: set 10 20 30 40 50 Enter the value of the variable $#: I understand ...
-4
votes
0answers
16 views

BASH— after getopts continues after exit [on hold]

in getopts(probably) it has two functions in it. One of them has exit at the end and there is also exit at the end of the option b. When I call it like this: ./name.sh -b. (without required argument) ...
1
vote
0answers
22 views

How do processes, jobs and session relate to each other ? [duplicate]

Could you deliver an answer in a way that does not require too much special knowledge in advance, yet also deliver some deeper insight to a lesser advanced Linux User ?
0
votes
1answer
44 views

Shell— print only certain lines from output

I need to choose from output only lines where number is bigger than chosen number. For example x=27 and I need to find only lines where the number in first column is bigger than that x. In this ...
1
vote
1answer
27 views

How to run a long running grep, pipe the result into less and put everything into background?

I often find myself in the situation where I need to find a code base for a given symbol like so: find src/galio -not -path './src/stapi-sdk/apilib/* -regextype posix-extended -iregex ...
0
votes
0answers
40 views

Shell splitting line into words without temporary file

yesterday I found out that this creates temporary file. Can anyone help me how to rewrite it so it wouldn't? I am desperate I have tried everything that I know, but it doesn't want to work. And also I ...
3
votes
3answers
102 views

Shell test to find a pattern in a string

I just wanted to ask whether there is any command which would work on common shells (bash, dash, kornshell)? It is supposed to check if the line variable contains any part of the path. if [[ $line =~ ...
1
vote
2answers
104 views

Why doesn't “rm -rf ./” delete anything?

The command rm -rf ./ does not do anything in a directory full of sub directories and files. Why so? Isn't -r supposed to go recursive? To add more confusion, it even prints an error message ...
2
votes
2answers
66 views

Print file contents and delete the printed content* from the file

In Linux, from a bash shell, how can I print the contents of a file and remove the content I just printed content from the file? I have a program writing texts to a file repeatedly. On a Linux shell ...
3
votes
1answer
24 views

Trailing colons and dash's builtin test command

What's the meaning of a trailing colon to dash's builtin test (or [) command? I was surprised when I found that if [ ... ]: ; then .. ; fi works (at all) in dash, but not bash, and it seems to be ...
-3
votes
0answers
33 views

Convert file pattern in Unix

I have a file with content as below 31/01/2014 1234 2234 4567 3321 ...n Need to write a shell script to convert the above file as below: DD_Date='31/01/2014' ...
20
votes
7answers
1k views

`command .*` acts on the parent directory

Someone of our team wanted to recursively change the user permissions on all hidden directories in a users home directory. To do so he executed the following command: cd /home/username chown -R ...
0
votes
1answer
49 views

can we get sorted grep output

I have same: 1.txt with apple written in it, 2.txt with mango written in it, 3.txt with apple written in it, 4.txt with mango written in it. grep -e apple -e mango *.txt will give result as: 1.txt: ...
6
votes
1answer
787 views

What is the meaning of 'ln -sf' in Linux?

I have 2 questions. First one is for the -sf options and second one is for the more specific usage of -f options. By googling, I figured out the description of command ln, option -s and -f. (copy ...
2
votes
3answers
55 views

What happens if I pass too few parameters to a shell function?

I would like to ask about passing parameters into functions. I tried this: function_name $var1 $var2 but usually (sometimes it printed error) it didn't make any difference whether I passed them or ...
2
votes
3answers
36 views

Command substitutions vs backslash escapes in a quoted string

Consider a double-quoted command substitution with backslash escapes inside it, like this: echo "$(echo '\\')" It prints out \\, whereas I would have expected it to print out only one backslash. My ...
0
votes
1answer
29 views

How do i write a shell script so that when i compile my c++ program it will put the binary into the Binary Directory

I have a directory called Binary and bunch of source files: ./ ├── Binary/ ├── lesson02.cpp ├── lesson04.cpp └── lesson06.cpp when I compile the source code g++ lesson01.cpp -o lesson01 I want ...
1
vote
2answers
47 views

Remove paragraph from file

I have a file (file.php) like this: ... Match user foo ChrootDirectory /NAS/foo.info/ ForceCommand internal-sftp AllowTcpForwarding no GatewayPorts no ...
1
vote
1answer
55 views

Brace expansion not working in a script

for i in {1..40} do echo $i done I got {1..40} and I would like to have something like 1 2 3 and so on so I can use the variable i inside a command's parameter.
1
vote
1answer
18 views

Switch-case block inside define keyword in a single logical line in a makefile

This is the code excerpt from ghc.mk, part of Haskell source compilation. I find it different, because the author has chosen to write one function block in a single line. Is it a common practice in ...
0
votes
4answers
62 views

Copy same specific parts of a file to another file

How can I copy same specific parts of a file to another file? In the first file, I have: user01: Id name nationality user02: Id name nationality . . . I want to copy each piece of information to a ...
2
votes
1answer
37 views

How to verify the target of a symbolic link points toward a particular path

Within a bash script, I know I can check if a file is a symbolic link with the following syntax if [ -L $path ] Does any one know how I would test if that path was linked to a particular path? E.g. ...
0
votes
0answers
33 views

How to get and print a user's public IP address in a Shell Script? [duplicate]

I've just completed a lengthy installation script that deploys a Ruby on Rails application unto web servers. At the end of this script, I'd like it to print something along the lines of: "Installation ...
-1
votes
1answer
30 views

Mutiple commands after sudo in one line

I want to execute multiple commands after a sudo command su - appuser -c "cd /apps/bundle/bundle-client/bin ; export BDL_WEB_USER=not_used ; export BDL_WEB_PASSWORD=not_used ; ./bundle -b ...
1
vote
1answer
34 views

Search for text inside java command output

I have a folder which have multiple Jar files. * dummy.jar * myjar-xx.jar * myjar-yy.jar Using find, I need to find first file starting with "myjar" Now, I want to grep the contents of ...
4
votes
1answer
48 views

Why does 'jobs' always return a line for finished processes when run in a subshell within a script?

Normally, when a job is launched in the background, jobs will report that it is finished the first time it is run after the job's completion, and nothing for subsequent executions: $ ping -c 4 ...
1
vote
1answer
33 views

How do I run a program without network access? [duplicate]

I am making a program that scrapes information from some web services. I want to test how my program reacts when it can't reach the web service, like if the web service is down or if the local ...