Tagged Questions
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, …).
0
votes
1answer
16 views
Editing the variable PATH
I want to start script just by typing script not the full path of the script for example ~/Desktop/name/script so i tried to edit variable PATH
PATH="$PATH:~/Desktop/name"
in the name folder i have ...
-2
votes
0answers
27 views
What will sed 's/it/this/1' p.txt will do in below example [on hold]
cat p.txt
cause i am only a crack in this castle of glass.
hardly anything there for you to see.
it is one of my favourite song.
listen it & you would love it.
sed 's/it/this/2' ...
11
votes
4answers
515 views
What exactly happens when I execute a file in my shell?
So, I thought I had a good understanding of this, but just ran a test (in response to a conversation where I disagreed with someone) and found that my understanding is flawed...
In as much detail as ...
1
vote
3answers
35 views
how to cut fields of a directory name?
I have directory named 140905_M01771_0112_000000000-ABBYT. I want to get the third field i.e. 0112. I tried:
cut -d _ -f 3 131230_M01771_0032_000000000-A7874
giving me error:
cut: ...
3
votes
1answer
32 views
Split file and know how many files were generated
I'm using the following lines to split a file into smaller parts:
split --line-bytes=100M -d $input $output/FILENAME
echo "$input was split into ??? 100MB files." >> demo.log
After that, I ...
0
votes
3answers
39 views
Help with tr command
Assume that the file ft has 25 lines of text. Explain the command:
tail -15 ft | tr "a" "A" > ft
and tell me how many lines the file ft has after the execution of the command.
I understand that ...
0
votes
0answers
14 views
the md5sum command cant find my archive [on hold]
I was testing a backup script and when the script attempt to make md5sums for the archive, it keeps saying "File Not Found" while the archive exist and I checked the spelling. Can anyone help, here is ...
0
votes
0answers
27 views
How can I define value in grep [on hold]
I want to calculate a date, then grep for that date but am having issues.
Can anyone offer advise on what's wrong with the below commands?
Date=$(date --date='1 day ago' +"%Y-%m-%d");
tar -czvf ...
1
vote
1answer
42 views
Sed command usage without defining variables in shell script
I have two variables
source_repo="fdl_ppe_01_04_repos_svc"
target_repo="fdl_ppe_01_10_repos_svc"
and I currently do a substitution within an XML file to replace all instances of $source_repo with ...
0
votes
1answer
29 views
Dash print expanded commands
Running xtrace or set -x with Bash will print the expanded command:
$ bash -xc 'touch "alfa bravo"'
+ touch 'alfa bravo'
However Dash does not print the command that is actually run:
$ dash -xc ...
2
votes
2answers
39 views
Passing a list of two PIDs to xargs only kills the first using ssh
I'm retrieving a list of two PIDs that I want to kill. My pipeline looks something like
ps -ef | grep foo | grep -v grep | awk {'print $2'} | xargs kill -9
Both processes are killed when executing ...
1
vote
2answers
35 views
set -u usage not working as expected
I am learning how to efficiently use different set options in my script and came across set -u that appears to be perfect for exiting my script if a variable does not get set properly (ex. deleting ...
-1
votes
0answers
25 views
Create desktop shortcut for program using shell [on hold]
I want to create a shell script that when I click on the icon a program automatically opens. Like for example the metasploit framework on Kali Linux
Also any tutorials on how to create something ...
5
votes
2answers
551 views
How can I add datetime to an existing file name in Linux?
I want to add date and time to the file name, for example: 08032016out.log.zip
This is what I try to do:
_now=$(date +"%m_%d_%Y")
_file="$_nowout.log"
touch $_file.txt # creating new file with the ...
-2
votes
1answer
32 views
CentOS 7 SSH errors
having a bit of an issue with SSH and my CentOS 7 server.
Here's a description of my problem.
I have open-ssh setup on my server, and am able to ssh in as root (The server is a remote server, and ...
1
vote
2answers
101 views
POSIX print function definition
Bash can print a function defintion:
$ bash -c 'y(){ echo z; }; export -f y; export -f'
y ()
{
echo z
}
declare -fx y
However this fails under POSIX Bash, /bin/sh and /bin/dash:
$ bash --posix ...
2
votes
3answers
76 views
Trying to understand .bashrc, env, and export
Disclaimer: Using bash.
I just need some confirmation / correction on my understanding of these things:
env is basically displaying the current environmental variables that are accessible to my ...
-1
votes
1answer
19 views
Create an application with GUI on Kali Linux [on hold]
I want to create a simple GUI application to work in Kali Linux. I only have experience with Visual Studio.
The application I want is pretty simple.
Just a user interface with buttons that when you ...
-3
votes
1answer
40 views
Meaning of this perl command [on hold]
I found this command perl -ne 'print $1 if m/\.([^.\/]+)$/' and I'd be very grateful if someone familiar with perl could tell me in a nutshell what exactly all the syntax means, it would save a lot of ...
0
votes
1answer
59 views
-r filename && . filename
i was just looking into a script i find this line. can anyone tell me what this line do. this is the code line.
[ -r "$PosConfigDir/posconfig.sh" ] && . "$PosConfigDir/posconfig.sh"
2
votes
2answers
53 views
Is `var=value builtin` the same as `var=value; builtin`?
In my answer here, I used the construct:
n=$1 shift
Reading Token Recognition spec, I understand that the shell will parse that line into two parts - the variable assignment n=$1 and the builtin ...
0
votes
0answers
19 views
What does echo *? [duplicate]
Recently I was writing a bash-script and added a line:
$ echo *
and got an output of file names and directory names.
What is the context of this list (just out of curiosity)?
3
votes
2answers
35 views
How to pin certain files when using sort?
Normally I am more creative with Unix commands and pipes, but not today.
So what I have is this:
collage.jpg
DCIM001.jpg
DCIM002.jpg
or this:
001.jpg
002.jpg
boston-collage.jpg
or sometimes
...
-3
votes
1answer
26 views
How do you disable command “chattr” in debian 8? [on hold]
# cat test2
ali is home
helo esi
how are you?
i`m fine.tanks
i`m fine.Tank you
# chattr +a test2
# vi test2
.
.
.
Press ENTER or type command to continue
1
vote
2answers
65 views
find “corrupt” file, nesting an if inside a find command
I'm trying to find "corrupt" files inside a directory structure, namely files which the file command would interpret as "data".
Here is the command I've been trying to run, but fails:
$ find . -type ...
3
votes
5answers
175 views
How shrink test -eq expression with more than one var value in /bin/sh
#!/bin/sh
if [ $num -eq 9 -o $num -eq 75 -o $num -eq 200 ]; then
echo "do this"
elif [ $num -eq 40 -o $num -eq 53 -o $num -eq 63]; then
echo "do something for this"
else
echo "for other do this"
fi
...
1
vote
2answers
51 views
Copy Files Based on Dates in Filename
I am having an issue when attempting to copy a range files from one directory to another based upon a date contained within the filename. The date in the filename is in UTC whereas the created dates ...
1
vote
1answer
39 views
Search bash history for already typed command
When I type ctrl+r and then start typing I can see what commands in the history match which is great.
Now is there a way to search the history on commands I have already typed in the terminal?
For ...
3
votes
2answers
64 views
Difference between parentheses and braces in terminal? [duplicate]
( du /etc; du /var; ) > tmp.txt
{ du /etc; du /var; } > tmp.txt
Is there a difference between the () and {}?
The output of tmp.txt seems exactly the same, and I was wondering whether i'm ...
3
votes
2answers
40 views
How call a function inside another function
I'm working actually in a shell script to monitor a server resources. I have a function and I want to know how can I call a second function inside the main one.
Example:
funct mainfunct(){
echo ...
0
votes
1answer
33 views
capture exit code and output of a command
There are similar questions, but mine is a little bit different. Or so I think. What I'd like to do is:
1.sh:
#!/usr/bin/env bash
set -eu
r=0
a=$(./2.sh || r=$?)
echo "$a"
echo "$r"
2.sh:
...
0
votes
2answers
170 views
Why we need to have 2>&1 in /dev/null 2>&1?
I saw in linux script there was a command argument > /dev/null 2>&1, I know it is to redirect the output to null, means silencing it. I also know about the numbering for 0,1,2 (STDIN, ...
16
votes
2answers
1k views
What does ${PATH:+:${PATH}} mean?
I recently noticed the following in my cygwin profile, more precisely:
/usr/local/bin:/usr/bin${PATH:+:${PATH}}
What does it mean? Why is not just $PATH? Is this an 'if $PATH exists then add ...
0
votes
2answers
30 views
Alert notification
I wrote simple script which is running all the time and whenever the size of a file is changed it will write something like "The size has changed" to terminal but instead of terminal message, is it ...
1
vote
5answers
68 views
Creating a permanent variable
Is it possible to set "permanent variable" in shell? For example,
when I log in I want to print message "Hello user, this is your xxx log in"
The number of logins would be stored in permanent ...
0
votes
1answer
26 views
How does the diff command handle caching?
I became curious when I was diffing two large (>326MB) files, and noticed that the second run took much less time than the first. This was frustrating, since I was trying to time the second run, to ...
0
votes
0answers
25 views
Adding source to PATH [closed]
I want to location to my $PATH so i can execute scripts using only .name .
I added command
PATH="$PATH:$HOME/bin
export PATH
to profile.user file
when i print "$PATH" its located there.
I ...
1
vote
3answers
41 views
How shell processes the content of command line in order to execute?
How shell processes the content of command line in order to execute?
Command first and then option and arguments.
Dividing command line into segments.
Processes from beginning to the end.
0
votes
1answer
31 views
Checking for mails
I recently started using mails via UNIX.
I would like to create a script , that would write (every time I log in ) something like
"The content of your mailbox has changed since last checkup"
...
3
votes
3answers
341 views
does head input > output copy all invisible characters to the new file?
I need to grab the first lines of a long text file for some bugfixing on a smaller file (a Python script does not digest the large text file as intended). However, for the bugfixing to make any sense, ...
1
vote
2answers
27 views
Shell script says system when to execute for the next time
I've got a shell script. It is supposed to be executed automatically on and on over time. Maybe about three times a day. But I don't want to write a cron job for it since it's not the same time every ...
0
votes
2answers
28 views
Why doesn't strace report that the parent shell fork() a child process before execve() a command?
strace runs a specified command until it exits. It intercepts and records the system calls which are called by a process and the signals which are received by a process.
When running an external ...
0
votes
3answers
44 views
How to write content of several files into a single one in Unix?
Suppose in a directory there are some files like:
file1.txt
file2.txt
file3.txt
file4
file5
fab
text1
I need to eliminate the files with the .txt extension and append the content of the ...
0
votes
2answers
30 views
exit code of the command **before** last? [duplicate]
I'm running a script within a script, release.sh and caller.sh (caller.sh calls release.sh). Both are bash.
release.sh contains a bunch of conditions with 'exit 1' for errors.
caller.sh contains a ...
2
votes
2answers
41 views
Grep only in files that are in certain folders
I want to grep for interesting string, but only in specific folder/file combinations, such as myfolder/myfile.out.
The directory I'm grepping from may have these combinations in subdirectories of ...
0
votes
1answer
11 views
tree command in a shell script doesn't append slashes for directories
I have a shell script executes tree command
$ cat _tree.sh
#!/bin/sh
tree -L 2 --charset ascii -I "_tree.sh|LICENSE|README.md|node_modules|nbproject"
$ sh _tree.sh
.
|-- bower.json
|-- dpl
|-- dst
...
1
vote
2answers
43 views
How can I CTRL^C out of a password prompt?
Say I started a su command, and I want to cancel it. Control+C doesn't work... I have to finish the prompt (either by getting the password wrong enough times or by getting it right).
Is there ...
0
votes
0answers
15 views
Redirect stderr to stdout and tee to file and check return value [duplicate]
I know how to redirect stderr and stdout to a file:
curl -sSo file http://foo.bar >> log 2>&1
I know how to get stdout to appear on the console and in a file:
curl -sSo file ...
0
votes
3answers
28 views
See content of sourced script
When I source a script in bash, is there a possibility to look at the script, that I just sourced, without accessing the script itself?
6
votes
3answers
616 views
Does the shell fork when I use built-in commands?
When I run the command type type, this gives me a result to standard output.
So, now I try this command:
type type > abc.txt
It redirects the standard output to abc.txt. So, if this command ...