Can't use alias in script, even if I define it just above!

Simply don't use aliases in scripts. It makes little sense to use a feature designed for interactive use in scripts. Instead, use functions:

somecommand () {
    ls -alF
}

Functions are much more flexible than aliases. The following would overload the usual ls with a version that always does ls -F (arguments are passed in $@, including any flags that you use), pretty much as the alias alias ls="ls -F" would do:

ls () {
    command ls -F "$@"
}

The command here prevents the shell from going into an infinite recursion, which it would otherwise do since the function is also called ls.

An alias would never be able to do something like this:

select_edit () (
    dir=${1:-.}
    if [ ! -d "$dir" ]; then
        echo 'Not a directory' >&2
        return 1
    fi
    shopt -s dotglob nullglob
    set --
    for name in "$dir"/*; do
        [ -f "$name" ] && set -- "$@" "$name"
    done
    select file in "$@"; do
        "${EDITOR:-vi}" "$file"
        break
    done
)

This creates the function select_edit which takes directory as an argument and asks the user to pick a file in that directory. The picked file will be opened in an editor for editing.

The bash manual contains the statement

For almost every purpose, aliases are superseded by shell functions.


To use interactive features like alias within a bash script you have to run it in an interactive bash shell. For that change the first line to include a -i . So your new script file becomes

#!/bin/bash -i
alias somecommand='ls -alF'
alias
somecommand 

Kind of a duplicate of a previous question however the answers there are kind of wordy. The short answer is that, for occult reasons, by default bash doesn't look at aliases defined inside scripts. You have to explicitly tell it to do so via a shopt -s expand_aliases line at the top of said script. Do that and then your script will find somecommand.