Hot answers tagged

64

Because -a means show all files. It is useful when combined with -l. As to why show those useless files when not using -l, because of consistency, and because Unix does not try to double guess what is good for you. There is an option -A (for at least GNU ls) that excludes these two (.., and .). Interestingly the idea of hidden files in Unix came about by a ...


41

Like is there a point to them showing up there? They show the ownership and permissions. That is often the most important thing to check when you have two users and one is saying they cannot see the other person's file that they were expecting to.


34

<$()> would be valid bash syntax for commands that read from a file (< part) where file names are created using command substitution ($() part) that redirect output to some other file (> part). Example: $ echo text > FILE $ wc < "$(echo FILE)" > WC_OUT $ cat WC_OUT 1 1 5 However, in the answer you linked to <$()> is used in the ...


14

The line returned by curl ends with carriage-return line-feed. (MS-dos line ending). The line-feed is removed by the Unix tools, however this leaves a carriage-return at the end. Fix this line to use dos2unix (and quote your argument to echo, avoiding the bugs described in BashPitfalls #14): version="$(echo "${tag//v}" | dos2unix)" ...or, using the shell'...


11

ctrl-alt-delor’s answer explains why you’re seeing this behaviour; but to address your underlying goal, I recommend using the GitHub API instead of interpreting the “latest” redirection: version=$(curl https://api.github.com/repos/gohugoio/hugo/releases/latest | jq -r '.tag_name | ltrimstr("v")') This asks the API for the information on the latest Hugo ...


8

As shown in https://ss64.com/bash/ls.html when you add the -a parameter to ls you get all entries, even those which begin with .; they are considered to be hidden entries, and not shown with a simple ls.


7

Is there a reason why they show up after ls -a? I'd wager a guess it's just a historical accident, like so many things are. According to a story by Rob Pike, "hidden" files (dotfiles) were created by something of an accident: Long ago, as the design of the Unix file system was being worked out, the entries . and .. appeared, to make navigation easier. ...


5

This ls option requires to show all files with ls -a... But the physical existence of . and .. in most filesystems is an artefact from the 1970s, when computers have been very tiny and people tried to find implementations that need only a small code size. This resulted in making hard links to the current directory and to the parent directory. Since more ...


4

<<< is a zsh operator now supported by a few other shells (including bash). read -a is bash-specific. ksh had read -A for that long before bash (consistent with set -A; set -a being something else inherited from the Bourne shell; also supported by zsh and yash) sh these days is an implementation or another of an interpreter for the POSIX sh ...


4

In Unix (folklore has it that by mistake) file/directory names starting with . weren't shown by ls (because names . and .. had been reserved for "this directory" and "parent of this directory", and showing them was considered useless clutter). So using that quirk people started using names like .profile or .something-or-other-rc (the RC is from Run Command, ...


4

You need to put the cd command inside the loop. The gotcha is that your paths are relative to your current directory, so the working directory must be reset back to the starting point at the beginning of each iteration in order for cd to work with your relative path. The ( ... ) subshell does that for us (the directory change lasts only for the scope of the ...


3

foo=bar && somecmd is pretty much the same as (since the assignment isn't likely to fail) foo=bar; somecmd which is the same as (on separate lines) foo=bar somecmd which is the assignment of a shell variable called foo, and then running a command somecmd. If foo is not exported (shell variables aren't by default), then it's not presented in the ...


3

If var contains the empty string, [ -n $var ] expands (after word-splitting $var) to the words [, -n and ]. That's the one-argument version of test, which tests if that single argument is non-empty. The string -n is not empty, so the test is true. In the GNU manpage, that's mentioned just after your quoted passage: -n STRING the length of ...


2

[[ is the "extended test" originating from ksh and also supported by bash/zsh so it should not recognize them. Additionally the == operator is not POSIX, = is the shell test operator for string comparison. These are two very common bashisms.


2

You're hashbang is /bin/sh and you are running the script with sh, which does not support the <<< herestring. If you use /bin/bash it will work. Additionally, while /bin/sh often supports arrays it is not required to do so, if an array is required you should use ksh, bash, zsh, or another shell that has support for them.


2

I guess the following script contains everything you need: #!/usr/bin/env bash # set defaults for used variables. # variables could be set this way: # var=foo var2=bar ./loopscript.sh max_runtime_sec=${max_runtime_sec:-180} recheck_time_sec=${recheck_time_sec:-5} while true; do # use pre-defined VAL or use default (output of sapcontrol) #...


2

To run successfully in cron such job you need to set some variables like ORACLE_SID, ORACLE_HOME and so on. The samples way to do this is to make your script on this way: source ~/.bashrc #or .bash_profile /oracle/GR1/121/bin/sqlplus / as sysdba <<EOF >> $LOGFILE whenever sqlerror exit sql.sqlcode; set echo on; set serveroutput on; STARTUP; EXIT ...


2

You can chain commands in one line via && such that they are executed sequentially - provided that all previous commands run successfully. Each runs in the shell as-is and doesn't modify the shell. Thus each gets the environment variables from the shell it is running in. $ LC_ALL=C && commandB --> execute LC_ALL=C, and if it returns 0 to ...


2

You can assign the output to a variable, then you can use pattern matching, for example: VAR1=ABCD01 echo ${VAR1##*[[:alpha:]]} This will remove all alphabetical characters from the variable and will print "01".


1

If it is only the last two characters you need from a few specific folders then there is also: echo ${VAR1:(-2)} or even (expanding on @RudiC) and choosing directories without any numerics except as the last two digits with GNU extended find find . -type d -regex "[^0-9]*[0-9][0-9]" -exec sh -c 'echo sapcontrol -nr ${1:(-2)} -function ...


1

Try $ find . -name "[A-Z]*" -type d | while read FN do echo sapcontrol -nr ${FN##*[A-Z]} -function GetSystemInstanceList done sapcontrol -nr 00 -function GetSystemInstanceList sapcontrol -nr 02 -function GetSystemInstanceList


1

as the design of the Unix file system was being worked out, the entries . and .. appeared, to make navigation easier No answer seems to see any use in these entries in the first place. They somehow stem from the hierarchical linked list. "Easy navigation": not with ls, but with a C program using readdir(3) or so. I believe .. went in during the ...


1

I think you are looking for pv (Pipe view): seq 100000000000 | pv -l | wc -l


Only top voted, non community-wiki answers of a minimum length are eligible